How do I add a property to my main camera and access it elsewhere?

I have added a script to my main camera with which I want to hold a public propety that is the maximum distance to the surface of my game.

I can set this public property in unity just fine. However, when I do Camera.main, I cannot find this property anywhere. I did some digging and googling and I can’t seem to find anything.

Does anyone know how to do this. I basically want to store the maximum distance on the camera and then use it for a raycast later in multiple object’s scripts.

Your script is stored as a component on the camera GameObject. You can use GetComponent to get the script reference, and then access the properties using that reference. There is a tutorial for this.

e.g…

YourScript script = Camera.main.GetComponent<YourScript>();
script.MyProperty = value;

In general, if you’re going to be updating properties often on the component you should store the reference to it rather than call GetComponent every frame.