I want to create a increasing numbers. for example 1-100. so i tried to invoke my number method in void Update (), it changes numbers very quickly. what i want is changing numbers every few seconds for ex after every 5 second it should increase number and show in GUItext. i also tried with thread sleep but still could not get exact result. please help me, thanks in advance.
Define a float number:
float myNumber;
Then in Update do this:
myNumber += Time.deltaTime * (1.0f / 5.0f);
There are a bunch of ways you could do this. You could try InvokeRepeat.
private var number : int = 0;
private var maxNumber : int = 100;
function Start(){
InvokeRepeating("CountNumber", 0, 5); //Repeat the CountNumber function, start after 0 seconds, repeat every 5 seconds.
}
function OnGUI(){
GUI.Label(Rect(900,20,300,300),String.Format("Number: "+ number)); //GUI display
}
function CountNumber(){
if(number >= maxNumber) {
number = maxNumber; //Making sure the number doesn't get larger than it is allowed to
CancelInvoke("CountNumber"); //This stops the method from repeating, It has already reached the max.
} else
number++; //Increase the number count by 1
}