Creating Particle System

Hi,

i want to create an element then i press the “fire 1” button. to this im using the following code:

if(Input.GetKeyUp(KeyCode.F))
{
Instantiate(obj, transform.position, transform.rotation);
}

But the problem is… i want to create a Particle System, soh what can i do to instantiate a new particle system??? i know that obj variable in the function must to be an configurated Particle system but how can i do that??

Thanks! :smile:

You could Instantiate a Prefab that’s already setup as a particle system or add the component yourself via scripting.

create a prefab with a particle system already setup or change the partcile settings once you have instantiated it.

if i want to use a prefab, how can i access my prefab??? and this will be saved on project or hierarchy tree?

create a prefab, drop your particle system on it, then in your script create a variable to hold the prefab and drop the prefab on the variable in the inspector view

but that’s the point, i dont want a static variable with one prefab, i have the script with one search to select the prefab and put it on the variable, so i need the script (c#) to let me create a new object of this prefab with that variable. understand?

Another way if it’s more easy… you can show me how can i create a Particle System with one variable to use it in the game. The objective is do something like a capsule who falling from a weapon in a shot. It’s just appear with a click.

Thanks

you can instantiate multiple copies of a prefab and assign different values to each copy.

You could have an array of different particle Prefabs you select… or load one of 1000s of particle Prefabs as a resource at runtime.

thanks guys, but any of you can post the code of how can i instantiate it here??

thanks