I’m not exactly sure why the booleans here are not changing, the script hit the portion where it plays the animation so it must be hitting the section where it should change to true but no change ever happens. I’ve tried disabling every part where the booleans are changed to false to see if maybe they were being changed back, but they just never change to begin with and I’m not sure what’s wrong.
Here’s the script:
var animObj : GameObject; //set the game object that is to be animated
var turningLeft = false;
var turningRight = false;
function Update(){
//if we push a or left arrow key,
//if boolean turningright is true
//play rightToLeft animation
//set boolean turningleft to true
//set boolean turningright to false
//otherwise
//set boolean turningleft to true
//and play turningleft animation
//if we push d or right arrow key,
//if boolean turningleft is true
//play leftToRight animation
//set boolean turningleft to false
//set boolean turningright to true
//Otherwise
//set boolean turningleft to false
//set boolean turningright to true
//and play turningright animation
//if we push w, the up arrow key, s or the down arrow key
//if the boolean turningleft is true
//play lefttostraight animation
//set turningleft to false
//if the boolean turningright is true
//play righttostraight animation
//set turningright to false
if (Input.GetKey("a") || Input.GetKey(KeyCode.LeftArrow) ) { //(left)
turningleft = true;
if (turningRight == true){
animObj.GetComponent.<Animation>().Play("rightToLeft");
}
else {
animObj.GetComponent.<Animation>().Play("turningLeft");
}
turningleft = true;
turningright = false;
}
else if (Input.GetKey("d") || Input.GetKey(KeyCode.RightArrow) ) //(right)
{
turningright = true;
if (turningLeft == true){
animObj.GetComponent.<Animation>().Play("leftToRight");
}
else{
animObj.GetComponent.<Animation>().Play("turningRight");
}
turningleft = false;
turningright = true;
}
else if (Input.GetKey("w")||(Input.GetKey("s")) || Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow) ) { //forward and back
if (turningLeft == true){
animObj.GetComponent.<Animation>().Play("leftToStraight");
}
else if (turningRight == true){
animObj.GetComponent.<Animation>().Play("rightToStraight");
}
turningleft = false;
turningright = false;
}
}
Any ideas or suggestion would be greatly appreciated!