Hi im trying to instantiate an object and i want that object to have a refrenced script inside it.
Im instantiating “houselvl1” and i want the “coinmanager” to be refrenced.
And you say its just to drag it inside there, yes but that doesnt work if i instantiate houselvl1, how do i script it so its refnreced when its being instantiated?
A prefab can’t save references to anything outside of its hierarchy. So a script on a prefab can save a reference to a component on itself, or on one of its children or grandchildren, but it can’t save a reference to a completely different object.
However, you can instantiate any GameObject, not just prefabs. What I usually do is make a “prelinked prefabs” object. It make it disabled and I put all my prefabs in there and look them up to other objects like game managers and resource pools. You can then instantiate game object from the scene and it’ll magically have references to other things in the scene where normally a prefab couldn’t have those. It saves me from having to use things like GameObject.Find and singletons and stuff to find the things it needs from the scene.
Ah thanks will just do that 