实例化只有一次产卵

时间:2015-11-25 00:27:59

标签: c# unity3d

我制作了一个防尘效果,它正在工作,但只工作一次,这是我的代码:

if ((Input.GetKey (KeyCode.UpArrow) && (grounded == false))){
            if (ativar < maxAtivar){
                Particula ();
                Destroy (GameObject.Find ("Poeira(Clone)"), delay);
            } 
        } 

Particula功能:

void Particula(){
    Instantiate (prefab, new Vector3 (player.transform.position.x, player.transform.position.y, 0), player.transform.rotation);
    ativar++;
}

我不知道如何重复这些,建议请:D

2 个答案:

答案 0 :(得分:1)

您希望将代码置于UpdateFixedUpdate方法中,如下所示:

void Update()
{
    ...
}

void FixedUpdate()
{
    ...
}

了解两者之间的区别非常重要。 FixedUpdate每帧运行一次,与物理引擎同步,而Update则不会。

答案 1 :(得分:0)

 Destroy (GameObject.Find ("Poeira(Clone)"), delay); **this destroys every dust object in your scene so;**
if ((Input.GetKey (KeyCode.UpArrow) && (grounded == false))){
            if (ativar < maxAtivar){
                Particula ();
               //close this Destroy (GameObject.Find ("Poeira(Clone)"), delay); 
            } 
        } 
    void Particula(){
       GameObject obj =(GameObject) Instantiate (prefab, new Vector3 (player.transform.position.x, player.transform.position.y, 0), 
      player.transform.rotation);
       Destroy (obj, delay); //destroy here 
        ativar++;
    }