in this script .the timer is reaching the 0 means then timer is going negative like -0.1 ,-0.2,-0.3…etc .But i want to stop my timer at 0.Please help me to solve this problem
var startTime:float;
var timeR:float;
function Start()
{
startTime=21.0;
guiText.material.color=Color.black;
}
function Update()
{
Countdown();
}
function Countdown(){
timeR =startTime - Time.time;
ShowTime();
if(timeR<0)
{
timeR=0;
TimeIsUp();
Debug.Log("TIME IS UP=" +timeR);
}}
function ShowTime()
{
var minutes:int;
var seconds:int;
var timeString:String;
minutes=timeR / 60;
seconds=timeR % 60;
timeString=minutes.ToString()+":"+seconds.ToString("00");
guiText.text=timeString;
}
function TimeIsUp()
{
Debug.Log("Time IS UP");
}
- snipped previous message.
Move your ShowTime call to after your below 0 check.
i cant understand what u trying to say
function Countdown(){
timeR =startTime - Time.time;
if(timeR<0)
{
timeR=0;
TimeIsUp();
Debug.Log("TIME IS UP=" +timeR);
}
ShowTime(); // Notice how this is after timeR is reset to 0
}
just change ur code with this below code. I just modified ur code littlebeat:
var startTime:float;
var timeR:float;
function Start()
{
startTime=21.0;
guiText.material.color=Color.black;
InvokeRepeating ("Countdown",0.0f,1.0f);
}
function Countdown(){
timeR =startTime - Time.time;
ShowTime();
if(timeR<0)
{
timeR=0;
CancelInvoke();
TimeIsUp();
Debug.Log("TIME IS UP=" +timeR);
}}
function ShowTime()
{
var minutes:int;
var seconds:int;
var timeString:String;
minutes=timeR / 60;
seconds=timeR % 60;
timeString=minutes.ToString()+":"+seconds.ToString("00");
guiText.text=timeString;
}
function TimeIsUp()
{
Debug.Log("Time IS UP");
}
Ram Thakkar @your scirpt is working but it stopping at -0.1 i want to stop the time at 0
I m really sorry, i just forgot to change the which i made,
just change this line:
if(timeR==0)
{
CancelInvoke();
guiText.text=“0.00”
TimeIsUp();
Or, better yet: Move the call to ShowTime after the check for 0. (See my code above and apply it to yours)
Otherwise if you want to change the way it’s displayed, you’ll have to change it twice rather than once.
thanks @dman
thanks @ram thaker both helped lot