How to get component of an object i instantiated during the game?

For example, I instantiates units during my RTS game.
The unit has a field of vision script that detect what they sees.
How do I return a “true” to another script that isn’t connected to the unit.
I need the unit to see the building before I can gain access to that building’s resource.
The problem is the unit sees the building, but the script that handles that doesn’t send anything to the screentoraypoint script that handles taking the resource.

The problem I found is that the newly instantiated unit is a gameObject by itself and doesn’t have any connection with the screentoray gameObject. How can I get the information to communicate ?

I’m kinda stuck on this for a few hours now :expressionless:

You can a reference to your script using the game object you instantiated (and calling getcomponent) on that.
If you provide a little more explanation, maybe I could help further more specifically. I think I understand, but just to be sure…

So, options are:

  • using a reference to the gameobject/script (or array/list thereof) and getting the value(s).
  • using your instantiated objects to "report " to whichever object(s) (/scripts) you want… ie: going the other way

There may even be other options, too :slight_smile: