- Home /
Question by
carter-carl30 · Jul 18, 2012 at 08:43 PM ·
timespeedcountdowntimedeltatime
Is it possible to have a gameobject in it's own timeframe?
Hi I have this script to speed up my game at 30 seconds on my countdown timer (see scripts below) however, at the moment the timer also counts down faster as the game speeds up. Is it possible to have the timer in it's own time(zone?) eg so the game speeds up at 30 seconds to go but the counter counts down at normal game speed?
SCRIPS:
SPEED UP TIME AT 30 SECONDS TO GO:
#pragma strict
var countdownTimer : countdownTimer;
function Update(){
if (countdownTimer.seconds <=30){
//speed up time x2
//Time.timeScale = 2f;
Time.timeScale += 0.1f * Time.deltaTime;
if (countdownTimer.seconds <=1){
//reset time to normal again
Time.timeScale = 1f;
}
}
}
COUNTDOWN TIMER:
//needs a 3d text object in scene named "Timer"
var seconds = 60;
private var textMesh : TextMesh;
function Start () {
textMesh = GameObject.Find ("Timer").GetComponent(TextMesh);
textMesh.text = seconds.ToString();
InvokeRepeating ("Countdown", 1.0, 1.0);
}
function Countdown () {
if (--seconds == 0){
if(Scorecounter.Counter > PlayerPrefs.GetInt("highscore"))
{
PlayerPrefs.SetInt("highscore", Scorecounter.Counter);
}
PlayerPrefs.SetInt("yourscore", Scorecounter.Counter);
CancelInvoke ("Countdown");
Application.LoadLevel(4);
}
textMesh.text = seconds.ToString();
}
Comment