Delay for bullet

Hello,

I want “delay” for bullet but coud not. I tried " yield WaitForSeconds()" but not worked.

my codes:

var Bullet : Transform;
var Speed = 16000;
var spawnPoint : Transform;
var SingleFire = true;

function Update ()
{

if(SingleFire==true){

if(Input.GetButtonUp(“Fire2”)){

var shot =Instantiate(Bullet, spawnPoint.transform.position, Quaternion.identity);

shot.rigidbody.AddForce(transform.forward * Speed);

} }

}

How can i add " WaitForSeconds()" for delay time ?

Thanks

If I understood you correctly:

// Instantiates a projectile off every 0.5 seconds,
// if the Fire1 button (default is ctrl) is pressed.

var projectile : GameObject;
var fireRate = 0.5;
private var nextFire = 0.0;

function Update () {
    if (Input.GetButton ("Fire1")  Time.time > nextFire) {
        nextFire = Time.time + fireRate;
        var clone = Instantiate (projectile, transform.position, transform.rotation);
    }
}

Actually, it’s a standard sample from Unity Script Reference. :slight_smile:

Thanks. it is working.
i m very new :slight_smile: