x


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.

more ▼

asked Feb 24 '11 at 05:05 PM

Muzz 1 gravatar image

Muzz 1
548 52 59 71

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

1 answer: sort voted first

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;
   }

}
more ▼

answered Feb 24 '11 at 05:11 PM

Alec Slayden gravatar image

Alec Slayden
1.2k 1 4 16

Thanks, that's great.

Feb 24 '11 at 05:35 PM Muzz 1
(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:

x5274
x3570
x249

asked: Feb 24 '11 at 05:05 PM

Seen: 404 times

Last Updated: Feb 24 '11 at 05:05 PM