- Home /
Power Up Script Problem!
I am making a simple jumping game and I have made a sphere which is going to be my power up. I want it so when I collide with the sphere, it sets the Time.timeScale to 0.5 for only 10 seconds. Then after the 10 seconds are up, it sets the Time.timeScale back to 1.
This is my current script:
function OnTriggerEnter ()
{
Destroy(gameObject);
Time.timeScale = 0.5;
}
Right now when I collide with it, it destroys the power up and set the Time.timeScale to 0.5, but I can't figure out how to do this for only 10 seconds?
Any help or scripts appreciated!
Answer by whydoidoit · Apr 13, 2013 at 08:43 AM
function OnTriggerEnter ()
{
Time.timeScale = 0.5;
yield WaitForSeconds(10 * Time.timeScale);
Time.timeScale = 1;
Destroy(gameObject);
}
Tried out script but does exactly what my old script used to do. It doesn't turn the time scale back to 1 after 10 seconds.
HELP!
Updated the answer, shouldn't have been destroying the object (because it stops the coroutine) until after the time out.
If you need it to be invisible for the time consider just moving it a long way at the start...
Your answer

Follow this Question
Related Questions
How to do seveal actions like scale on an object one after another? 2 Answers
Speed = 11 meters /s plane is 110 meters should take me 10 seconds but it dosn't 0 Answers
Loading A Level After 40 Seconds 2 Answers
Animation Window: How to scale keyframes to increase time? 9 Answers
Decreasing object size until a certain size over time? 2 Answers