- Home /
Adding a value to a variable every second?
I want to make a script that adds the value of 1 to a variable every second. Then, when the player hits Space, the value of the variable will appear on the screen. The problem is, I have absolutely no idea how to make the value of one be added to a variable every second.
So, how do I make the value of one be added to a variable every second? Is there a way?
               Comment
              
 
               
              take float
 public float timer = 1f;
and then add this as update
 timer = timer + Time.deltaTime;
 debug.log(timer);
and as time.deltatime it will add 1 on each second but don't take integer or you can choose invoke as tanoshimi said .
Answer by tanoshimi · Jan 04, 2015 at 08:24 AM
Specifically,
 #pragma strict
 
 var myNumber : int;
 
 function Start () {
     InvokeRepeating("AddOne", 1, 1);
 }
 
 function AddOne() {
     myNumber += 1;
 }
Thanks! After one look at InvokeRepeat on the scripting API, and a couple glances at your script, I was able to get a working count up timer. Thanks again!
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                