Cross script communication

I have a prefab called an “Orange” which has a script attached called “Orange”. I then have a second object called “Cursor” attached to which is a script called “Cursor”. Cursor is not a prefab - it is just an object in the Level.

Now Orange exists nowhere in the level, but is created using Instantiate. One is created every 5-10 seconds so there can be quite a few in the level at the same time.

My Cursor object has a box collider which is a trigger on it. When an Orange object is in the trigger I would like to be able to read a value called CountDown from the Orange object.

I’m stuck, no matter which way I try this I keep ending up with various different scripting errors. Can anyone help me out? Please?

Can you post the scripts you are using, and which errors the current state gives you?

// Inside Cursor.js ...
function OnTriggerEnter( collider ) {
   var orangeInstance : Orange;

   orangeInstance = collider.GetComponent(Orange);
   
   print(orangeInstance.CountDown);
}

Thanks! That worked perfectly.