- Home /
Question by
Ryzu · Feb 19, 2017 at 10:57 PM ·
gameobjectprefabparticlesystemaddcomponent
Adding prefab ParticleSystem to a GameObject?
Hey, Id like to add a already premade ParticleSystem to my Main Character, because I have multiple Characters with different particles. I dont want to make a prefab for every single Character. My approach would have been this:
public GameObject[] obj;
// Use this for initialization
void Start () {
if (!PlayerPrefs.HasKey("CharSelected"))
{
PlayerPrefs.SetInt("CharSelected", 1);
}
int pchar = PlayerPrefs.GetInt("CharSelected");
switch (pchar)
{
case 0:
Destroy(this.gameObject.GetComponent<ParticleSystem>());
this.gameObject.AddComponent(obj[0].GetComponent<ParticleSystem>());
}
}
But AddComponent only lets me add a Type of a Component, not a premade one. How could I solve this?
Comment
Your answer
Follow this Question
Related Questions
How to add a prefab containing Animation to a GameObject? 1 Answer
Adding Prefab Components 1 Answer
Spawn blood particle system prefab where sword hits enemy 1 Answer
Why would the clone of a particle effect not work? 0 Answers
Prefab connected to empty gameobject with scripts, empty moves, prefab doesnt? 2 Answers