- Home /
Unity fire1 prefab in code
Hello everybody,
I'm very new to Unity so excuse me if I'm asking or doing something illogical.
I have imported a tree model and on mouse click, I am emitting the particles from the Fire1 prefab. Currently, i'm doing that like this: http://pastebin.com/hNA3K6ch
Now I want to create the Fire1 prefab on runtime when I click somewhere. I already have the raycasting setup so positioning is not a problem but I have no idea how to create the Fire1 prefab on runtime. Can somebody help me with this?
Answer by ScroodgeM · Jul 23, 2012 at 09:38 PM
you can't "create prefab at runtime"
if you want just to make clones of object you can use Instantiate() method. it takes an original of object and makes a clone.
Answer by Pondomaniac · Dec 13, 2013 at 10:38 AM
Here are the steps.
Make sure you create a directory called “Resources” and place it in your Assets/ directory.
Create a prefab. Let’s all it “FooPrefab”.
In C#, instantiate the prefab as follows:
GameObject go = Instantiate(Resources.Load("FooPrefab")) as GameObject;
Your answer
Follow this Question
Related Questions
Increasing And Decreasing An Array Through A Variable 2 Answers
Need help with my script 0 Answers
Prefabs and variables 1 Answer