as DeathQuake said, just create a public property or variable to assign your script. But I would change it to
“public GameObject Cam;”
and attach your cam instead, because the Camera already created an instance of player, so you just need to get that script
“var playerScript = Cam.GetComponent();”
and you can then simply use all public stuff from it
“playerScript.LevelUp();”
or whatever
Thanks very much for the answers.
Sorry, I should have specified a little more, or I might not understand entirely - my apologies if this is a simple concept I don’t understand yet.
The ‘player’ class instance is not attached to any physical gameObject, it’s instantiated through the World class.
Is there any way to reference the variables in the instance without attaching it to a gameObject first?
Well you might have two other options, the first one, you already mentioned, is to make it static, but instead of making the class static, how about using a singleton pattern for a GameManager Script and instantiate the player there, that way you can use the instance of the GameManager to access the player class, without making it static. So just the GameManager is basically Static that holds the classes and stuff you need.
Another Option would be to search for the Camera, so GameObject.Find(“NameOfObject”).GetComponent(); that way you can get the script without attaching it first to a GameObject, but it comes with a cost in performance (depends on how often and intense you gonna use it) as many suggest to avoid the Find method.
Maybe you can also use some kinda event that pushes the player class information to another script that listens for it, but that would also be an overkill for a simple class reference. So the best way would be using a GameObject property and assigning it within the Unity Inspector. Is there a specific reason why you don’t like to use it that way?
Consider passing in the reference when you create the object. You have full control of the constructor, if a certain reference is needed, make it manadatory.