Not sure why this isn’t working but it will only run the forward function, then it won’t acknowledge a click on going back. I have a feeling its got to do with function OnMouseDown(). Can’t determine what the issue is though.
var cam : GameObject;
var hasMovedLeft : boolean;
function Start()
{
cam = GameObject.Find("Main Camera");
}
function OnMouseDown()
{
if (gameObject.tag == "up" && hasMovedLeft == false)
{
MoveForwardLeft();
hasMovedLeft = true;
}
if (gameObject.tag == "down" && hasMovedLeft == true)
{
MoveBackLeft();
hasMovedLeft = false;
}
}
function MoveForwardLeft()
{
Debug.Log("REACHING UP STATEMENT");
cam.animation["cameraLeft"].speed = 1.0;
cam.animation.Play("cameraLeft");
}
function MoveBackLeft()
{
Debug.Log("REACHING DOWN STATEMENT");
cam.animation["cameraLeft"].speed = -1.0;
cam.animation["cameraLeft"].time = cam.animation["cameraLeft"].length;
cam.animation.Play("cameraLeft");
}
Are you changing the tag of your gameObject somewhere else in another method? If not, you need to change the tag from “up” to “down” at some point if you want the second if block in your OnMouseDown to work.