x


Control amount of bullets

Im using the script

var projectile : Rigidbody;

var speed = 50;

function Update () {

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

projectile.tag = "Bullet";

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

Destroy(clone.gameObject, 3);

}

How can i make it so i can control the amount of bullets instantiated each second

more ▼

asked Feb 15 '12 at 06:05 PM

fireomega gravatar image

fireomega
356 5 7 9

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Thank you works perfectly

more ▼

answered Feb 15 '12 at 06:58 PM

fireomega gravatar image

fireomega
356 5 7 9

(comments are locked)
10|3000 characters needed characters left
var projectile : Rigidbody;
var speed = 50;

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

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

        lastShot = Time.time;
    }
Destroy(clone.gameObject, 3);
}

You use a simple if statement to check if a certain time has passed so we can fire again.

more ▼

answered Feb 15 '12 at 06:50 PM

LegionIsTaken gravatar image

LegionIsTaken
452 24 30 34

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3337
x1679
x446
x309
x275

asked: Feb 15 '12 at 06:05 PM

Seen: 446 times

Last Updated: Feb 15 '12 at 06:58 PM