Quantcast
Channel: Latest Questions by Gillissie
Viewing all articles
Browse latest Browse all 93

how to reference uninstantiated prefab?

$
0
0

I have a script that gets attached to a game object through code when the time is right. The script instantiates another game object (an emitter) from a prefab. However, I can't seem to figure out the best way to reference the prefab that I want to instantiate.

I have tried using a var and assigning the prefab to the picker for the script, but since the script isn't attached to an object yet, this doesn't work (although it seems like it should). The "default references" for the script is assigned, but isn't honored by Unity when I AddComponent() the script.

In case you're wondering why, the script component isn't part of the object by default because the object doesn't need the behavior until a certain thing happens. In this case, it is a treasure object and it just sits there until the player picks it up. When the player picks it up, I add the CollectTreasure script, which handles everything related to picking it up, including instantiating a one-off emitter to show some sparkles when picked up.


Viewing all articles
Browse latest Browse all 93

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>