Can't get MoveTowards() to work

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 …

What is that target you want to reach? If you try to move your camera to another GUI content in your scene, make sure the rendermode of your Canvas is not in overlay or screenspace mode as in this case it doesn’t matter where the camera is pointing at. The GUI stuff just moves with it. In overlay and / or screenspace mode you have to move the content inside the canvas. You can use an empty gameobject (with RectTransform) as parent for all GUI stuff and move that inside your Canvas.

Well, just reread your question. If it moves correctly in one case but not the other it’s most likely that your other position is wrong (0,0,-5) or that you reset your booleans somewhere else immediately.