I have an ‘options’ button and a ‘back’ button and if they are pressed the camera in the scene moves towards a target. When the ‘options’ button is pressed the camera moves to the desired position but when I press the ‘back’ button the camera won’t move. I can’t figure out what’s going on.
public void LateUpdate(){
if (optionsButtonPressed == true && backButtonPressed == false) {
// Move the camera's position between it's current position and it's new position.
newPosition = Mathf.MoveTowards(camera.transform.position.x,-7,Time.deltaTime * 20);
camera.transform.position = new Vector3(newPosition, 0,-5);
}
if (backButtonPressed == true && optionsButtonPressed == false ) {
// Check to see that if conditions have been met(they have)
print ("yahadad");
// Move the camera's position between it's current position and it's new position.
newPosition2 = Mathf.MoveTowards(camera.transform.position.x,7,Time.deltaTime * 20);
camera.transform.position = new Vector3(newPosition2, 0,-5);
}
}
…
public void OnMouseUp(){
if (gameObject == optionsButton) {
backButtonPressed = false;
optionsButtonPressed = true;
}
if (gameObject == backButton) {
optionsButtonPressed = false;
backButtonPressed = true;
}
print ("optionsButtonPressed = " + optionsButtonPressed + " Camera Position: " + camera.transform.position);
print ("backButtonPressed = " + backButtonPressed + " Camera Position: " + camera.transform.position);
}
Here is the console output:
// When options button is pressed:
optionsButtonPressed = True Camera Position: (0.0, 0.0, -5.0)
backButtonPressed = False Camera Position: (0.0, 0.0, -5.0)
// When back button is pressed:
optionsButtonPressed = False Camera Position: (-7.0, 0.0, -5.0)
backButtonPressed = True Camera Position: (-7.0, 0.0, -5.0)
yahadad
yahadad
yahadad …