How to set Camera positions using GUI Buttons.

Hello everyone, I am making a 2D game. The game contains 4 GUIbuttons onscreen. I want to assign a different camera position to each 4 GUIbutton. Right now when i click a button the camera moves for example 5.0f, but when I click it again the camera moves again in that direction.
I want it to work so that I can only press that button once, after that you can’t (or the button will be grayed out). I don’t want to use + 5.0f but rather a camera position values like (x,y,z).
Anyone willing to help me?

using UnityEngine;
using System.Collections;

public class GUI_Button : MonoBehaviour
{
	public Texture2D buttonImage = null;
	public Texture2D buttonImage2 = null;
	public Texture2D buttonImage3 = null;
	public Texture2D buttonImage4 = null;

	private void OnGUI()
	{
		GUI.backgroundColor = new Color(0,0,0,0);
		if (GUI.Button(new Rect(398, 656, 114, 112), buttonImage))
		{
		transform.position += new Vector3(0, 5.0f, 0);
		}
		if (GUI.Button(new Rect(521, 656, 114, 112), buttonImage2))
		{
			transform.position += new Vector3(0, -5.0f, 0);
		}
		if (GUI.Button(new Rect(644, 656, 114, 112), buttonImage3))
		{
			transform.position += new Vector3( 6.671f, 0, 0);
		}
		if (GUI.Button(new Rect(767, 656, 114, 112), buttonImage4))
		{
			transform.position += new Vector3( -6.671f, 0, 0);
		}
	}
}

Firstly i’d make 4 cameras for each screen you want and what you can do is putthem in variables like so:

Public Gameobject Camera1;
Public Gameobject Camera2;
Public Gameobject Camera3;
Public Gameobject Camera4;

then you can add a script to each button:

void OnMouseDown()
{
  //script to switch between camera
}

IF your Camera is fixed throughout the game you can set the positions instead of adding them. you always want to check what position your at but using an array of bools on your buttons. I gave them an id called switchpos and made it a variable. I also moved you transform code out of OnGUI for neatness. I haven’t put in the “greyed” out texture but you can do that in each of the if blocks in update().

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour
{
    public Texture2D buttonImage = null;
    public Texture2D buttonImage2 = null;
    public Texture2D buttonImage3 = null;
    public Texture2D buttonImage4 = null;

    int switchpos = -1;
    bool[] cam = new bool[4];
    Vector3 defualt_pos;

    public void Start()
    {
        defualt_pos = transform.position;
    }
    public void Update()
    {

//Switching 
            if (cam[0] && switchpos != 0)
        {
            switchpos = 0;
            transform.position = defualt_pos + new Vector3(0, 5.0f, 0);

            //set diaabled button image here
      }
        else if (cam[1] && switchpos != 1)
        {
            switchpos = 1;
            transform.position = defualt_pos + new Vector3(0, -5.0f, 0);
            //set diaabled button image here
        }
        else if (cam[2] && switchpos != 2)
        {
            switchpos = 2;
            transform.position = defualt_pos + new Vector3(6.671f, 0, 0);
            //set diaabled button image here
        }
        else if (cam[3] && switchpos != 3)
        {
            switchpos = 3;
            transform.position = defualt_pos + new Vector3(-6.671f, 0, 0);
            //set diaabled button image here
        }
    }
    public void OnGUI()
    {
        GUI.backgroundColor = new Color(0, 0, 0, 0);
       
        cam[0] = (GUI.Button(new Rect(398, 656, 114, 112), buttonImage));
        cam[1] = (GUI.Button(new Rect(521, 656, 114, 112), buttonImage2));
        cam[2] = (GUI.Button(new Rect(644, 656, 114, 112), buttonImage3)); 
        cam[3] = (GUI.Button(new Rect(767, 656, 114, 112), buttonImage4));
       
    }
}

As I said I haven’t added the texture swap for you, but that really isn’t that hard. there are probably more tweaks to be found but I’ll leave those up to you.

Hope it helps