When a button is Pressed how will I get the camera to move to another Position?

Hello I really could use some help with this:

I have a button which is attached to a game object and is interacted within the real world space. I also have a camera that moves around a game object. How would I once the button is pressed get the camera to move to a specific Position or to the button that has been pressed. (just to say this is being developed for android)

I really could use some help with this, Thank you!

There are countless ways for you to do this but hopefully these instructions will give you a better idea of what you need to do. For my solution I wrote a script with two main functions which move a transform to a new position. One function uses a parameters specified on the script (vector position and a bool to determine if we’re moving in world space or local space) and the other moves the transform to the same world position of another transform.

using UnityEngine;
using System.Collections;

public class TransformMover : MonoBehaviour 
{
	public Transform targetTransform;
	public Vector3 position;
	public Vector3 rotation;
	public bool useWorldSpace = true;
	public float tweenDuration = 1.0f;


	private Coroutine _currentCoroutine = null;



	public void MoveToPosition()
	{
		if (targetTransform != null)
		{
			if (useWorldSpace)
			{
				targetTransform.position = position;
			}
			else
			{
				targetTransform.localPosition = position;
			}
		}
	}

	public void MoveToRotation()
	{
		if (targetTransform != null)
		{
			if (useWorldSpace)
			{
				targetTransform.rotation = Quaternion.Euler(rotation);
			}
			else
			{
				targetTransform.localRotation = Quaternion.Euler(rotation);
			}
		}
	}


	public void TweenToRotation()
	{
		if (_currentCoroutine != null)
		{
			StopCoroutine(_currentCoroutine);
			_currentCoroutine = null;
		}
		
		if (gameObject.activeInHierarchy && targetTransform != null)
		{
			Quaternion targetRotation = Quaternion.Euler(rotation);
			_currentCoroutine = StartCoroutine(TweenRotate(tweenDuration,targetRotation,useWorldSpace));
		}
	}



	public void MoveToTransformPosition(Transform target)
	{
		if (targetTransform != null && target != null)
		{
			targetTransform.position = target.position;
		}
	}

	public void MoveToTranformOrientation(Transform target)
	{
		if (targetTransform != null && target != null)
		{
			targetTransform.position = target.position;
			targetTransform.rotation = target.rotation;
		}
	}

	public void TweenToTranformOrientation(Transform target)
	{
		if (_currentCoroutine != null)
		{
			StopCoroutine(_currentCoroutine);
			_currentCoroutine = null;
		}

		if (gameObject.activeInHierarchy && targetTransform != null && target != null)
		{
			_currentCoroutine = StartCoroutine(TweenMoveRotate(tweenDuration,target));
		}
	}

	public void TweenToTranformPosition(Transform target)
	{
		if (_currentCoroutine != null)
		{
			StopCoroutine(_currentCoroutine);
			_currentCoroutine = null;
		}
		
		if (gameObject.activeInHierarchy && targetTransform != null && target != null)
		{
			_currentCoroutine = StartCoroutine(TweenMove(tweenDuration,target));
		}
	}

	public void TweenToTranformRotation(Transform target)
	{
		if (_currentCoroutine != null)
		{
			StopCoroutine(_currentCoroutine);
			_currentCoroutine = null;
		}
		
		if (gameObject.activeInHierarchy && targetTransform != null && target != null)
		{
			_currentCoroutine = StartCoroutine(TweenRotate(tweenDuration,target));
		}
	}

	public void TweenToRotation(Transform target)
	{
		if (_currentCoroutine != null)
		{
			StopCoroutine(_currentCoroutine);
			_currentCoroutine = null;
		}
		
		if (gameObject.activeInHierarchy && targetTransform != null && target != null)
		{
			_currentCoroutine = StartCoroutine(TweenMove(tweenDuration,target));
		}
	}


	private IEnumerator TweenRotate(float duration, Quaternion targetRotation, bool worldSpace)
	{
		Quaternion startRotation = worldSpace ? targetTransform.rotation : targetTransform.localRotation;
		
		float t = 0;
		float timeElapsed = 0;
		
		while (timeElapsed < duration)
		{
			timeElapsed += Time.deltaTime;
			t = timeElapsed/duration;

			if (worldSpace)
			{
				targetTransform.rotation = Quaternion.Lerp(startRotation, targetRotation,t);
			}
			else
			{
				targetTransform.localRotation = Quaternion.Lerp(startRotation, targetRotation,t);
			}
			yield return null;
		}

		if (worldSpace)
		{
			targetTransform.rotation = targetRotation;
		}
		else
		{
			targetTransform.localRotation = targetRotation;
		}
	}




	private IEnumerator TweenMoveRotate(float duration, Transform target)
	{
		Vector3 startPosition = targetTransform.position;
		Quaternion startRotation = targetTransform.rotation;

		float t = 0;
		float timeElapsed = 0;

		while (timeElapsed < duration)
		{
			timeElapsed += Time.deltaTime;
			t = timeElapsed/duration;

			targetTransform.position = Vector3.Lerp(startPosition, target.position,t);
			targetTransform.rotation = Quaternion.Lerp(startRotation, target.rotation,t);
			yield return null;
		}
		targetTransform.position = target.position;
		targetTransform.rotation = target.rotation;



	}

	private IEnumerator TweenMove(float duration, Transform target)
	{
		Vector3 startPosition = targetTransform.position;
		
		float t = 0;
		float timeElapsed = 0;
		
		while (timeElapsed < duration)
		{
			timeElapsed += Time.deltaTime;
			t = timeElapsed/duration;
			
			targetTransform.position = Vector3.Lerp(startPosition, target.position,t);
			yield return null;
		}
		targetTransform.position = target.position;
	}

	private IEnumerator TweenRotate(float duration, Transform target)
	{
		Quaternion startRotation = targetTransform.rotation;
		
		float t = 0;
		float timeElapsed = 0;
		
		while (timeElapsed < duration)
		{
			timeElapsed += Time.deltaTime;
			t = timeElapsed/duration;
			
			targetTransform.rotation = Quaternion.Lerp(startRotation, target.rotation,t);
			yield return null;
		}
		targetTransform.rotation = target.rotation;
	}

}

You can attach this script component to any object in the scene but it’s best you attach it to your button. On your button, set the click event to reference the object that contains the TransformMover component and select one of the two functions MoveToPosition or MoveToTransformPosition. Your button inspector should look something like this.
55199-screen-shot-2015-09-29-at-45928-pm.png

This script also has a few tween methods to different positions and rotations via values specified in the inspector or you supply a transform to tween to. You could also use animation to move your objects and have the animation play on the button press. Again, this isn’t the only way to implement this feature. Ultimately the design of your program should determine how you go about moving objects on clicking a button.

@ Dr-Nick how can I play animation of main camera on the button press?
Please help me…

fantastic script - very powerful
thanks Dr-Nick
by using tween to transform I could add a target that teh camera tweens to