- Home /
When I try to increment a variable by 1, why does it add 10?
In my code, i wrote
   function CoUpdate ()
     {
         while (GameManager.xMovement > 0)
         {
             transform.position.x += GameManager.xMovement + .01*Deleter.timesDestroyed;
             yield WaitForSeconds(1);
             GameManager.totalMovement++;
             if (GameManager.hasFallen == true)
             {
                 //xMovement -= .001;
             }    
         }
     }
The part that is causing concern is the GameManager.totalMovement++;, because when I view the variable within Unity as my game is playing it increments by 10 instead of by 1. Why is this? The code to display the variable is
 #pragma strict
 
 var sphere : Transform;
 public static var hasFallen = false;
 public static var xMovement = .085;
 public static var totalMovement = 0;
 var xMovement2 = .085;
 var totalMovement2 = 0;
 public static var waitDone = false;
 
 function Start () {
 
 }
 
 function Update () 
 {    
     xMovement = xMovement2;
     totalMovement2 = totalMovement;
     if (sphere.position.y <= -20)
     {
         hasFallen = true;
     }
     
 }
Also, when I try to increment a variable by a decimal, the value does not display in Unity as it updates in real time. Why is this?
               Comment
              
 
               
              Answer by memetic-arts · Jun 25, 2014 at 10:01 PM
Try declaring totalMovement as a float, not an int. You can't add ints and floats together.
 private var totalMovement = 0.00;
Your answer
 
 
             Follow this Question
Related Questions
A node in a childnode? 1 Answer
How to expose variables in c# according to selected booleans 1 Answer
I can't go to unify wiki 2 Answers
Ref modifier 1 Answer
FPS Graphics problem 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                