I’m developing an small space game,the enemy has a super simple AI that basically is to shot at each 2 seconds,I tried to do this:
var shotE:GameObject;
function Update () {
shot();
}
function shot()
{
yield WaitForSeconds(2.0);
var balaj=Instantiate(shotE,transform.position,transform.rotation);
}
But it’s shoting like a crazy:shock:,how can I fix this bug?
If you don’t need any extra features, you can use InvokeRepeating.
var shotE : GameObject;
function Start () {
InvokeRepeating ("shot", 2, 2);
}
function shot () {
var balaj=Instantiate(shotE,transform.position,transform.rotation);
}
Sorry, I’d forgotten a line in the code that I gave. Oops.
Dman, thanks for your help - I’d never known about InvokeRepeating, and am going to change several of my current project’s scripts to use it. It certainly cuts down on the number of lines!