How to reference a GameObject to a script inside my Pre

Hi guys, I need help referencing my Player GameObject to a Prefab.


Since it’s now missing I don’t know how to reference it through code

This is the GameObject I’m trying to reference to a prefab.

Please Help me. Thank you

Not sure exactly what you are asking. If you are trying to reference the prefab itself, you just drag it from where it is in your assets folder to the field in the inspector. If you are talking about a GameObject you instantiated from a prefab, you would use the reference to that GameObject returned from Instantiate and in your code assign it to that field in your script.

Well since Prefabs can’t save references from GameObjects, I was hoping to find a code for my Player GameObject to be referenced from my Target Script on the Asteroid prefab. Target script lets the object move towards the player.

So when you instantiate the player, you use the returned reference to the player in your Target script.