- Home /
Spawn and set as child
Hi . I have character in my game and if it hits the wall in high speed blood particles instatiates in game .Problem is that blood is not following main character - blood particles juct spawns in and stays in same spot and that looks stupid. So what I want is to instatiate blood particles as child of main character so that blood follows main character. How can I do that? Here is my code......
public GameObject bloodSplash;
void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.tag == "Surface") {
Instantiate (bloodSplash, transform.position, Quaternion.identity);
} }
Answer by look001 · Jan 17, 2018 at 10:18 PM
adding the transform object of your character to the Instantiate method should simply do the trick. After that you have something like this:
Instantiate (bloodSplash, transform.position, Quaternion.identity, transform);
Answer by bhavinbhai2707 · Jan 17, 2018 at 10:29 PM
store the instatiated blood particles in a variable
Gameobject go = Instantiate (bloodSplash, transform.position, Quaternion.identity);
and then set the go variable as child of character
//transform.SetParent(Transform Parent)
go.transform.SetParent(character.transform);