hi,
i am making an endless runner and i need to increase the speed of certain gameobjects when the timer reaches 0. im using the following script. The timer and movement work fine but speed changes for only a fraction of a second.
movement.js
// Building movement
static var speed;
speed = -10;
function Update () {
var x = Time.deltaTime * speed;
transform.Translate(x, 0, 0);
}
and this is the countdown timer
countdowntimer.js
private var startTime;
private var restSeconds : int;
private var roundedRestSeconds : int;
private var displaySeconds : int;
private var displayMinutes : int;
var countDownSeconds : int;
function Awake()
{
Reset();
}
function Reset()
{
startTime = Time.time;
}
function OnGUI () {
//make sure that your time is based on when this script was first called
//instead of when your game started
var guiTime = Time.time - startTime;
restSeconds = countDownSeconds - (guiTime);
//display messages or whatever here -->do stuff based on your timer
if (restSeconds == 0) {
movement.speed-=5;
Reset();
}
//display the timer
roundedRestSeconds = Mathf.CeilToInt(restSeconds);
displaySeconds = roundedRestSeconds % 60;
displayMinutes = roundedRestSeconds / 60;
text = String.Format ("{0:00}:{1:00}", displayMinutes, displaySeconds);
GUI.Label (Rect (400, 25, 100, 30), text);
}
please help.
im pretty new to coding. Thanks