[Solved] Expecting Identifier Error?


The way you are doing GetComponent is wrong.

FirstCamera.GetComponent.<Camera>().enabled = true;

instead you should do it like this

FirstCamera.GetComponent<Camera>().enabled = true;

There is no dot after GetComponent instead inequality signs with the object or class you want get.

“Unity GetComponent scripting”

Here is the correction to the code :

if(Input.GetKeyDown("f")) 
    {
        FirstCamera.GetComponent<Camera>().enabled = false;
        SecondCamera.GetComponent<Camera>().enabled = true;
    }

    if(Input.GetKeyDown("r"))
    {
        FirstCamera.GetComponent<Camera>().enabled = true;
        SecondCamera.GetComponent<Camera>().enabled = false;   
    }

Also

public UnityEngine.Camera FirstCamera;
public UnityEngine.Camera SecondCamera;

in the above two variable declaration case you don’t need to declare them using UnityEngine.Camera rather you can directly declare them as

public Camera FirstCamera;
public Camera SecondCamera;

Because you have already defined the UnityEngine namespace at the very top of the file so you don’t need to use it while referring to the classes of that namespace.

solved Expecting Identifier Error?