- Home /
Question by
jimmyismike · Jun 20, 2011 at 06:57 PM ·
gunshootreload
Reloading script
Here is my gun script
var prefabBullet:Transform;
var shootForce:float;
function Update()
{
if(Input.GetButtonDown("Fire1"))
{
var instanceBullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
instanceBullet.rigidbody.AddForce(transform.forward * shootForce);
}
}
How can i edit this script so it can only shoot 8 times. Then you have to press r to make it be able to shoot again?
Comment
format code by selecting it all, and hitting the 010101 button.
Best Answer
Answer by flaviusxvii · Jun 20, 2011 at 07:09 PM
This should get you started.
if(Input.GetButtonDown("Fire1") && ammo > 0)
{
var instanceBullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
instanceBullet.rigidbody.AddForce(transform.forward * shootForce);
ammo--;
} else if(Input.GetButtonDown("r")) {
ammo = 8;
}
Your answer
Follow this Question
Related Questions
No Reload Script Works 1 Answer
Reload/Shoot Animation 3 Answers
Wrote a script for Shooting, reloading and to display the AMMO in a GUIText 1 Answer
1 script doesn't react to input 1 Answer
reload gun with bullets 2 Answers