- Home /
Unity android button and Time.timescale problems
Hi. I`m making a car game and i have problems with the pause button meaning , i use Time.timescale=0 to pause but i also use Time.timescale=0 on diffrent game events such as collisions and countdowns that end the game.This script contains both the pause button components and the game ending situations.So the problem is that each fragment works independent meaning that the pause button works but when i add the other fragment it stops working and viceversa. I `m really stuck on this and cant figure a workaround, i would really like some help on this.thanks in advance.
var x:float=2560;
var y:float=1600;
var TextStyle = new GUIStyle();
var TextStyle2 = new GUIStyle();
var TextStyle3 = new GUIStyle();
var time : float;
static var timeScale : float;
var image : Texture; //fuel texture
var image2 : Texture; //gameover texture
var paused : boolean = false;
var btnTexture : Texture;
function OnGUI ()
{
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3(1.0*Screen.width/x, 1.0*Screen.height/y, 1.0));//resolution scale
var Cooldown : String = "Fuel "+(60-Mathf.Round(Time.time)+CarsCOLLISION.Timer);
GUI.DrawTexture(new Rect(100, 1250, 340, 340), image); //fuel
GUI.Label (Rect (1500, 20, 1000, 100),"Score "+(Mathf.Round(Time.time)*7+CarsCOLLISION.Score), TextStyle);//score
GUI.Label (Rect (120, 1200, 2560, 1600),"Fuel "+(60-Mathf.Round(Time.time)+CarsCOLLISION.Timer), TextStyle2);//countdown timer
if(Cooldown == "Fuel "+0)// end game when fuel is empty
{
GUI.DrawTexture(new Rect(350, 300, 1920, 1080), image2);//post image game over
Time.timeScale = 0;
}
else { Time.timeScale = 1;
}
if (GameObject.Find("player car") == null)// end game on collision with police
{
GUI.DrawTexture(new Rect(350, 300, 1920, 1080), image2); //post image game over
Time.timeScale = 0;
}
if (GUI.Button(Rect(10,10,100,100),btnTexture)&& paused == false)//pause button
{ Time.timeScale = 0;
paused =true;
}
if (GUI.Button(Rect(40,40,100,100),btnTexture)&& paused == true)//resume button
{ Time.timeScale = 1;
paused =false;
}
}
Answer by Dan.R · Dec 04, 2012 at 05:54 PM
else { Time.timeScale = 1;
}
I have deleted this line and everything runs like clockwork:)
Your answer
Follow this Question
Related Questions
Unity GUI Button Options 0 Answers
Play a video ingame by clickin on gameobject 3 Answers
GUI Button appears when Paused 1 Answer
A node in a childnode? 1 Answer
Custom GUI Button is Black 1 Answer