Shooting Question

Ok, I have a ship at the bottom of the screen right now that when I press Fire1 it shoots a bullet. Thank you for the help on that by the way. Now I want to be able to hold it in and shoot. I had it where the ship while Fire1 was held just fired hundreds of bullets. Thats not quite what I was looking for. I want it to shoot every half second or second if Fire1 is held in. Can someone point me in the right direction? I searched for some answers and some got close but not quite what I was looking for.

Thank you!

2 Answers

2

var projectile : Rigidbody;

var speed = 20;

function Update () {

if ( Input.GetButtonDown (“Fire1”)) {

clone = Instantiate(projectile, transform.position, transform.rotation);

clone.velocity = transform.TransformDirection( Vector3 (0, speed, 0));

Destroy (clone.gameObject, 3);

}

}

Figured I would put my code for my “shoot” function up

var projectile : Rigidbody;
var speed = 20;
var fireRate = 0.11;

private var lastShot = -10.0; // Dont touch!

function Update () {
    if(Input.GetButton("Fire1") && Time.time > fireRate+lastShot){
        clone = Instantiate(projectile, transform.position, transform.rotation);
        clone.velocity = transform.TransformDirection( Vector3 (0, speed, 0));

        Destroy (clone.gameObject, 3);

        lastShot = Time.time;
    }
}

This will check if enough time has passed and will shoot one bullet if true. Very simple.

And please, do not post your comments/edits in answers, you should have edited your question instead.