Hello I’m working on a simple power up that allows the player to slow down. Here’s the script I’m using:
var mySkin : GUISkin;
function OnGUI () {
GUI.skin = mySkin;
if (GUI.Button (Rect (10, 50, 80, 30), "Slow Down")) {
var script4 = GetComponent("Movement");
script4.enabled = false;
var script5 = GetComponent("Movement - Easier");
script5.enabled = true;
}
}
What I’m having trouble with is keeping the power up only active for a certain period of time before it becomes deactivated and the player’s movement returns to normal.
I was kindly provided a coroutine script at another forum:
var mySkin : GUISkin;
function OnGUI () {
GUI.skin = mySkin;
if (GUI.Button (Rect (10, 50, 80, 30), "Slow Down")) {
StartCoroutine( SlowDown( 2.0 ) );// deactivate for 2 secs
}
}
function SlowDown( float deactivateInSeconds )
{
var script4 = GetComponent("Movement");
script4.enabled = false;
var script5 = GetComponent("Movement - Easier");
script5.enabled = true;
yield WaitForSeconds( deactivateInSeconds );
script5.enabled = false;
script4.enabled = true;
}
But that’s as far as I was able to get. I realise that ‘deactivateInSeconds’ is an Unexpected token so I removed it and tried to play around with the coding, with limited knowledge, to no avail. I’m not sure what to do.
Any answers or feedback would be greatly appreciated. -Ben