Accessing main camera componet

I have attached a component to my main camera that I want to access from a script. This is the code I am using:


Where OrbitCamera is the script and FreeCam() is a function in it that I want to call but I get this error:

Null Referance Exception: Object referance not set to an instance of an Object.
Please Help.


OrbitCamera orbitCameraScript = Camera.main.GetComponent<OrbitCamera>();


The code is correct for C# (it should have a dot before in JS).
Probably GetComponent can’t find the script OrbitCamera, which produces this error.
Let’s check the possibilities:

1- OrbitCamera is JS and your script is C# (or the other way around): JS and C# are compiled by different compilers, thus they can’t see each other during compilation - but already compiled programs can be seen by any language, thus you can place OrbitCamera in one of the early compiled folders (Plugins, Standard Assets and Pro Standard Assets) and the code above in another Assets folder (Assets/Scripts or whatever).

2- The camera isn’t tagged MainCamera (what would let Camera.main empty);

3- The script OrbitCamera is actually attached to a child object, or to another camera.

I just realized the error that shows on the bottom of the screen was from the previous compilation and that the code actually works(I am very new to unity and still getting used to the interface). Sorry for wasting everyone’s time like this.