- Home /
Setting a time limit
When a character gets certain power-up enemies will go slower, but i only want it to last for a certain amount of time, how can i do this?
Answer by karl_ · Sep 08, 2010 at 06:05 AM
Set a static boolean for the enemies to check, and when the character triggers the power-up, set the boolean appropriately to prevent your enemies from moving quickly. From there have a timer for your enemy scripts to set the boolean back to true.
*Note that I did not test any of this in Unity, it's just an example of how I might achieve this result.
For example, inside your power-up script:
function OnTriggerEnter(other : Collision)
{
// You may want to add an if check here to make sure it is the
// player entering your powerup
enemyScript.enemySlowDown = true;
}
And for your enemies:
var timeToSlow : float = 5.0; // This will be the amount of seconds to slow your enemies private var countDown : float; static var enemySlowDown : boolean = false;
function Awake() { countDown = timeToSlow; }
function Update() { if (enemySlowDown) // Check to see if character has hit the powerup { countDown -= 1 * Time.deltaTime; // Begin countdown in actual time if(countDown <= 0) // If countdown is finished reset everything { enemySlowDown = false; countDown = timeToSlow; } } }
GREAT script, everything slows down just like should, but the timer doesn't work. they just stay slow, and i didn't change anything.
Your answer
Follow this Question
Related Questions
Code to Set 3 ADS per day limit 1 Answer
Limiting the time my gun can shoot 1 Answer
Set limit to 60 seconds 2 Answers
Keep score after restart & limit ads/hour 1 Answer
Limited Energy Regeneration 3 Answers