- Home /
One use per level question
OK, in my game I want the player to be able to use a powerup once per level. I'm guessing you do this with a Boolean, starting off with it being true, and being false afterwards. I can't get this to work, so here's my script. Where should I put the Boolean, and what should I write? Am I completely wrong altogether?
var prefab : GameObject; function Update() { if(Input.GetButtonUp ("Fire1")) Instantiate( prefab, transform.position, Quaternion.identity ); }
Thanks.
Answer by Alec-Slayden · Feb 24, 2011 at 05:11 PM
If we assume that the instantiation is the powerup, you can use the boolean as follows:
var prefab : GameObject; var hasPowerup : boolean = true;
function Update() {
if(Input.GetButtonUp ("Fire1") && hasPowerup){ Instantiate( prefab, transform.position, Quaternion.identity ); hasPowerup = false; }
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613110054im_/https://answers.unity.com/themes/thub/images/avi.jpg)