i have 2 camera in my 2D scene. i want to change the player camera to another one. but it gives me error
here is the error:
MissingComponentException: There is no 'Camera' attached to the "player" game object, but a script is trying to access it.
You probably need to add a Camera to the game object "player". Or your script needs to check if the component is attached before using it. SwitchCamera.Start () (at Assets/scripts/SwitchCamera.cs:10)
this is my code:
public Camera camera1;
public Camera camera2;
void Start () {
//camera2 = GameObject.Find("Player").GetComponentInChildren<Camera>();
camera1 = transform.FindChild("player").gameObject.camera;
}
void Update()
{
if (Input.GetKeyDown (KeyCode.C)) {
camera1.GetComponent<Camera> ().enabled = true;
//camera2.GetComponent<Camera>().enabled = true;
}
}