Unity C script (Multi_Cameras)

I have done some Googling. I found a lot of scripts referring to Java but I have yet to find one for C. What I want to do is be able to assign two camera’s like they did in the Java script but using C. I am semi new to coding in C so I need a bit of help calling back so you can set the camera’s inside the GUI. I already have the if statement wrote out for being able to swap the cameras. I haven’t figure out how to assign the camera using C. How can I assign the cameras? I would be just as happy setting them in the script or drag and dropping in them in the GUI. Either or is fine.

Sean

I assume you mean C#. I did a quick search and converted come Unityscript into c# for you. You could use an array if you have too many cameras:smile:

Camera camera1;
Camera camera2;

void Update (){

if (Input.GetKeyDown("c")){

if (camera1.enabled == true){

camera1.enabled = false;
camera2.enabled = true;

}

else

{

camera1.enabled = true;
camera2.enabled = false;

}

}

}

}

I do have a small problem. I keeps complaining about camera 2 being null. It’s not assigned.

Ok, I fixed the first problem. I just simply did the following.

public class Cameras : MonoBehaviour 
{	
	public Camera Camera1;
	public Camera Camera2;

However, it’s not switching cameras now. Here is my code for this.

// Use this for initialization
	void Start()
	{
		Camera1.enabled = true;
		Camera2.enabled = false;
	}
	
	// Update is called once per frame
	void Update() 
	{
		// Switch camera views
		if( Input.GetKeyDown( KeyCode.Tab ) ) // First to 3rd
		{
			Camera1.enabled = false;
			Camera2.enabled = true;
		}
		else //Switch back
		{
			Camera1.enabled = true;
			Camera2.enabled = false;
		}	
	}
}