- Home /
Create a power up that last for a specific time
Hi! I making a videogame of shooting and when you hit a specific object you earn 10. The thing I need is create a power up that when you take it, the quantity that you earn duplicates for 10 seconds. I'm using yield waitforaseconds.
What's the actual question you want answering? If your using yield WaitForSeconds then just get a function to run when the player picks up the item, duplicate the pickup, do the yield for 10 seconds and change the pickup amount back.
If you want to do this more than once you'll have to create a timer that counts down every frame. Add an amount to the timer every time you pick up the power up, and when the timer is greater than zero, double the pickup amount. Then you just need to -= 1 from the timer each update if it's greater than 0.
Answer by DESTRUKTORR · Apr 28, 2013 at 09:07 PM
If this is the only multiplier you'll be using, simply add a boolean to the class that handles the scored-pickups (not the powerup), then, set the powerup such that when you pick it up, it sets that boolean to true, and calls Invoke("DeactivatePowerup", powerupTime);
where powerupTime
is the time (in seconds) that you want the powerup to last for, and make a void method (or function, if you're using javascript) in that same class, with the method signature void DeactivatePowerup()
(or function DeactivatePowerup() : void
, in javascript) in which you will set that boolean back to false.
If you are using other multipliers, multiply the incoming score by a float field stored in that monobehaviour, for the score multiplier, and simply add 2 to it (or multiply it by 2, depending on how you want it to affect it) and in the DeactivatePowerup()
method, in stead of setting a boolean to false, you'll be doing the opposite operation you applied to the multiplier when the powerup was activated.
I apologize if this seems at all convoluted, but given no source to work with, I can't be of much more help than this.
Your answer
Follow this Question
Related Questions
Is there any difference if I duplicate a prefab in Hierarchy or drag it from Project tab? 1 Answer
Duplicating meshes without instantiating? 2 Answers
Unity3D - Ammo Texture repeat 2 Answers
How to start the animation of a duplicate object on a different frame 1 Answer
How do i get a GameObject in the Hierarchy view to duplicate from gameobject1 to gameobject2 0 Answers