Accessing a Class From Another Script

This is probably a foolish question but is there a possibility to access a class from another script? I know you can attach it to a gameobject then get the script from the component. But for my case I’m using a class that holds my coins so that they can be saved. The saving script accesses the file no problem. But when I apply the same logic to another script it gives me an error " ‘somescript’ is never assigned to, and will always have its default value null" `public class CoinTracker
{

private int _coins; 

public CoinTracker ()
{

}
public CoinTracker(int coins)
{
    _coins = coins; 
}

public int coins
{
    get
    {
        return _coins;
    }
    set
    {
        _coins = value; 
    }
}

}
`
And then the “SomeScript:MonoBehaviour” is like this:

{
    
    private CoinTracker coinTracker;


    // Start is called before the first frame update
    void Start()
    {
        
       

        Debug.Log(coinTracker.coins); 

    }

 
}

I am just really confused because the “Saving” script accesses the “Cointracker” class just like it is shown in the “SomeScript”. Any light or possible ways to access the class directly if possible would be awesome. Thank you!!

public class MyClass : MonoBehaviour
{
//lots of fun stuff in this class
}

Above is the script you want to access from another script, which is below:

public MyOtherClass : MonoBehaviour
{

[SerializeField] MyClass firstScript;

}

Now in the inspector, just click on the little circle to the right of the field and it will show you the instances of the type your looking for if they exist and you put it in there.

In your case you had better use Singleton for CoinTracker if you want only one instance of this class:

public class CoinTracker
{
	public static CoinTracker Instance { get; private set; } = new CoinTracker();

	private CoinTracker(){ }

	public int Coins { get; set; }
}

Now you can get Coins from anywhere and without assigning it in Inspector every time:

public class SomeScript : MonoBehavior{
        void Awake(){
               print(CoinTracker.Instance.Coins);
        }
}