How do i change the position of a camera using the new UI button?

Hi All,

So hopefully this is an easy question for someone! I have the following simple script that changes the position of the camera based on a key press.

private Vector3 newPosition;

void Awake ()
	newPosition = transform.position;

void Update ()

void PositionChanging ()
	Vector3 positionA = new Vector3(-50, 3, 0);
	Vector3 positionB = new Vector3(500 , 3, 0);

		newPosition = positionA;
		newPosition = positionB;

	transform.position = newPosition;


I would like to change this so that the two positions are controlled by two UI buttons i have created using the Unity 4.6 UI. I assume i change the “Input.GetKeyDown” parts of the code? Or do i call it through the “onClick” field in the button itself?

Any help is gratefully received. It’s been driving me mad…



Attach this script to your camera:

using UnityEngine;
using System.Collections;

public class CameraPos : MonoBehaviour {

	//Must be public
	public void ChangePos1() {
		transform.position = new Vector3(-50f, 3f, 0f);

	//Must be public
	public void ChangePos2() {
		transform.position = new Vector3(500f, 3f, 0f);

Follow the images:

Thanks!! That works great!