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