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: #pragma strictprivate var _tree : GameObject;//Fireprivate var _fire : - Pastebin.com

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?

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.

Here are the steps.

  1. Make sure you create a directory called “Resources” and place it in your Assets/ directory.
  2. Create a prefab. Let’s all it “FooPrefab”.
  3. In C#, instantiate the prefab as follows:

GameObject go = Instantiate(Resources.Load(“FooPrefab”)) as GameObject;