How to Access Base C# Classes Within a monobehaviour Event

How do you get an instance of a non-monobehaviour C# class that belongs to another object?

I can create an instance of the base C# script and access its properties just fine when it relates to the script that called it, but say I gave a script component attached to an object a set of statistics of type Stats (that I the programmer made up in another file) and another script needed to access values of that specific stats instance?

Like if a nacho.cs script wanted the getHunger() operation specific to the player.cs script and not nacho.cs, how would I do that?

I should probably mention that using GetComponent() to do this throws an error.

TL;DR: how do I make other.csclassname.getVariable() work and is it possible?

Inside your Nacho script, declare a public variable of type Player.

public Player eatingPlayer;

In the editor, drag your Player scene object, over this field, which should now be visible in your Nacho object. Only GameObjects that contain a Player component will be valid for drag onto this field.

Now you can access any public members of the Player, via this field.

eatingPlayer.statistics.foo();

One last note

It is good practice to double check the user: it’s possible that a player has NOT been dragged onto this field, leaving it blank (null). You should check that the player object is valid, before accessing it’s members.

if(eatingPlayer!=null)
{
   eatingPlayer.statistics.foo();
}