我制作了一个防尘效果,它正在工作,但只工作一次,这是我的代码:
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
答案 0 :(得分:1)
您希望将代码置于Update
或FixedUpdate
方法中,如下所示:
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++;
}