- Home /
Boolean values not behaving as expected. Please Help?!
I have a mouseOver script (see below) that I'm using in a project that is used with the Kinect controller. So you actually "click" or "select" things by hovering over them for a long enough time.
The last if statement is where I noticed this problem. I'm trying to prevent the "zoomIn" and "zoomOut" button detection while any of these three booleans are true: 
 zoomedIn, movingUp, movingDown
The Problem: The print() at the 2nd to last line of the below code ALWAYS returns false. But I know that's not true, because if I comment out any of the places where those booleans are set to "true", the iTweens don't happen or it skips other functionality that I would expect. So it seems there's something about checking them on Update() or that somehow the booleans are getting reset. I know for a fact that these booleans do not exist in any other scripts in the scene.
It should be noted that this script is attached to a prefab that is instantiated several times procedurally via another script. (You can mouseOver any of them and that object is animated, zoomed in on, etc.
I have spent hours and hours on this, and I'm stumped. I feel like it must be something obvious.
 private var hovering : boolean;
 private var movingUp : boolean;
 private var movingDown : boolean;
 private var zoomedIn : boolean;
 private var cameraStartPos : Vector3;
 private var cameraStartRot;
 private var yearTextWasHidden : boolean;
 private var mainCamera : GameObject; 
 private var zoomTargetPos : Vector3;
 private var clicked : boolean;
 
 var duration : float = 5;
 var zoomTarget : GameObject;
 var yearText : GameObject;
 var descriptionText : GameObject;
 var closeBtn : GameObject;
 var ticker : GameObject;
 var cameraOutPos : Vector3;
 
 function Start() {
     mainCamera = Camera.main.gameObject;
     cameraStartPos = Camera.main.transform.position;
     cameraStartRot = Camera.main.transform.rotation;
 }
 
 function OnMouseEnter() {
     yield WaitForSeconds(.5);
     if(!zoomedIn){
         startTimer();
         Camera.main.SendMessage("cursorHover");
     }
 }
 
 
 function OnMouseExit() {
     Camera.main.SendMessage("cursorRestore");
     clicked = false;
     StopAllCoroutines();
 }
 
 function exitZoom() {//This gets called from another script, when the 'close' button is 'pressed'
     movingDown = true;
     moveDown();
     descriptionText.renderer.enabled = false;
     closeBtn.renderer.enabled = false;
     if(yearTextWasHidden){
          yearText.renderer.enabled = false;
     }
 }
 function startTimer() {
     yield WaitForSeconds(1);
     clicked = true;
 }
 
 function moveUp() {
     ticker.renderer.enabled = false;
     iTween.MoveTo(mouseMovement.selected,{"name":"moveItemUp","position":Vector3.Scale(mouseMovement.itemStartPos,Vector3(1,3,-3)),"time":2,"EaseType":"easeInOutCubic","oncomplete":"upComplete"});
     iTween.MoveTo(mainCamera,{"name":"moveCameraUp","position":zoomTargetPos,"time":2,"EaseType":"easeInOutCubic"});
     iTween.RotateTo(mainCamera,{"name":"rotateCameraUp","x":0,"y":0,"time":2,"EaseType":"easeInOutCubic"});
 }
 
 function moveDown() { 
     iTween.MoveTo(mouseMovement.selected,{"name":"moveItemDown","position":mouseMovement.itemStartPos,"time":2,"EaseType":"easeInOutCubic","oncomplete":"downComplete"});
     iTween.MoveTo(mainCamera,{"name":"moveCameraDown","position":cameraStartPos,"time":2,"EaseType":"easeInOutCubic"});
     iTween.RotateTo(mainCamera,{"name":"rotateCameraDown","x":9.3,"y":19.0,"time":2,"EaseType":"easeInOutCubic"});
 }
 
 function moveOut() {
     iTween.MoveTo(mainCamera,{"name":"moveCameraOut","position":Vector3.Scale(cameraStartPos,Vector3(1,1,2)),"time":1.5,"EaseType":"easeInOutCubic"});
 }
 
 function moveIn() {
     iTween.MoveTo(mainCamera,{"name":"moveCameraIn","position":cameraStartPos,"time":1.5,"EaseType":"easeInOutCubic"});
 }
 
 function upComplete() { 
     iTween.StopByName("moveItemUp");
     iTween.StopByName("moveCameraUp");
     iTween.StopByName("rotateCameraUp");
     movingUp = false;
     zoomedIn = true;
     mainCamera.transform.position = zoomTarget.transform.position;
     mainCamera.transform.rotation.x = 0;
     mainCamera.transform.rotation.y = 0;
     descriptionText.renderer.enabled = true;
     closeBtn.renderer.enabled = true;
 }
 
 function downComplete() {    
     iTween.StopByName("moveItemDown");
     iTween.StopByName("moveCameraDown");
     iTween.StopByName("rotateCameraDown");
     movingDown = false;
     zoomedIn = false;
     mainCamera.transform.position = cameraStartPos;
     mainCamera.transform.rotation = cameraStartRot;
     descriptionText.renderer.enabled = false;
     closeBtn.renderer.enabled = false;
     ticker.renderer.enabled = true;
     mouseMovement.selected = null;
 }
 
 function Update() {
     if(clicked){
         if(!zoomedIn && !movingUp){
             mouseMovement.selected = gameObject;
             mouseMovement.itemStartPos = transform.position;
             zoomTargetPos = Vector3.Scale(zoomTarget.transform.position,Vector3(1,3,1));
             if(!yearText.renderer.enabled) {
                 yearText.renderer.enabled = true;
                 yearTextWasHidden = true;
             }
             movingUp = true;
             moveUp();
         }
     }
 
     if(!zoomedIn && !movingUp && !movingDown){
         if (Input.GetButton("zoomOut")) {
             moveOut();
         }
         if (Input.GetButton("zoomIn")) {
             moveIn();
         }
     }
     print(zoomedIn + " " + movingUp + " " + movingDown);
 }
Your answer
 
 
             Follow this Question
Related Questions
The public bool will not change unless i set it 1 Answer
Why won't my if result to true? 1 Answer
Boolean problem. 1 Answer
Engine Only Returns Responses for False 2 Answers
Boolean problem!! 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                