this code creates an infinite amount of boxes while I hold the fire button down and then it propels them. I’m wondering, how can I make it shoot one box at a time. I put the Wait function everywhere and it doesn’t change
Do not listen to smaika. You cannot have a yield in update.
here’s what your code should read:
#pragma strict
var projectile : Rigidbody;
var clone : Rigidbody;
function Update(){
if(Input.GetButtonUp("Fire1")) {
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection (Vector3.forward * 100);
}
Using get button “up” will call the action once, while get button will call the action whenever the button is down. There is also getbuttondown if you want to do something immediately, once (before the user lifts their finger off the key).