An instance of type 'Script' is required to access non static member 'Variable'

An instance of type ‘MoneyScript’ is required to access non static member ‘CurrentMoney’.??? i made it a public variable and yet that doesnt work … im trying to call in another variable from my money script so when i kill an enemy (RIGIDBODY) i get an extra $50 to my CurrentMoney

my variables for my money script

public var CurrentMoney : float = 0;
var MoneyGUI : GUI;

var Rigid50 : GameObject;
var Rigid100 : GameObject;
var Rigid150 : GameObject;

ai damage script

function ApplyDamage (Damage : float) {


      if(CurrentHealth < 0){
      
         return;
      
      }


   CurrentHealth -= Damage;
   
   if(CurrentHealth == 0){
   
   
     Destroy( gameObject );
      MoneyScript.CurrentMoney += 50;
     
     
   
   
   }


}

You’d only use

MoneyScript.CurrentMoney

if CurrentMoney is a static variable. If it’s a public, non-static, you should be using

GetComponent to access it. If the script you are using to call your moneyscript is attached to the same gameObject as moneyscript, you’d do something like:

var mScript : Component = GetComponent(MoneyScript);
var curMon : float= mScript.CurrentMoney;

OR

var curMon : float = GetComponent(MoneyScript).CurrentMoney;

My JS skills are kinda rusty, so have a look at the link I’ve provided to the Unity Script Reference for GetComponent.

If the script you are using to call MoneyScript is attached to another gameObject, you’d define that gameObject, easy way would be to use a public var to assign go in inspector.

var go : GameObject;
var mScript : Object = go.GetComponent(MoneyScript);
var curMoney : float = mScript.CurrentMoney;