Have a small script, dont know how to add a burst mode, please help

Hello all, been trying to google the issue with little luck in this case. Additionally the search function does not seem to be working so I thought I would ask directly. I am attempting to add an adjustable “burst” mode (like a 3 round burst) with an adjustable cooldown after it to this script but dont know how or where to insert it, I am very new to programing so please be patient. Current script:

var Bullet : GameObject;
var activeUnit=false;

function Update (){
if (activeUnit==true){
if(Input.GetButton(“Fire3”)){
var bullet = Instantiate(Bullet, GameObject.Find(“1GunL”).transform.position, transform.rotation);

bullet.rigidbody.AddForce(transform.forward * 10000);
Destroy (bullet, 5);
}
}
}

Thank you for any assistance,

G~

So you have a projectile, moving and you want to give it some more force? A burst? Look up AddForce.Impulse.

No no, sorry, I mean a burst mode like a 3 round burst. so essentially, fires a certain amount of rounds and then you are unable to fire again for a certain amount of time.

Use limits.

Var limit : int;

Also, since the button will ring true as long as it is pressed, once every 33milliseconds, you’ll want to adjust your code slightly to something like this…

If input . Getbutton( fire button 3)
If firing == true
Return
If firing == false
{
Firing = true
Invokerepeating(“fireGun”, 0.1, 1.0);
}

function fireGun()
{
BulletCount++;
If (BulletCount >= bulletLimit)
{
cancelInvoke(fireGun);
Yield WaitForSeconds2);
BulletCount = 0;
}
Fire gun stuff here
}
Firing = true;

I will start messing around! I appreciate the information greatly :slight_smile: thanks alot for the assistance.

What you want to do is Burst shots… Such as fire 3 shots with one press?

You should use a loop. A for loop for instance.

for(int i = 0; i < myBurstCountVar; i++)
{
   //Do the code that fires the weapon.. It will fire as many times as the myBurstCountVar is. 
}

Btw Whats with all the non [ CODE ] [ /CODE ] Brackets?