- Home /
Particle system play too late (c#)
Hi, i have a problem with a simple blood partcle system. I want to play the bool particles before the player death. To make this i have done this script:
using UnityEngine; using System.Collections;
public class collisione : MonoBehaviour {
public ParticleSystem blood;
void OnCollisionEnter2D (Collision2D coll)
{if (coll.gameObject.tag == "triangolo") {
blood.Emit(100); //emit 100 blod particles
GameObject.Find ("Main Camera").GetComponent<lives>().morte(); //decrease the player lifes
Destroy (this.gameObject); //destroy the player gameobject
}
}
}
This script work but it plays the particles after the player respawn. I want to see the particles on the player collison with triangle tagged objects
it respawn calling the function morte that is into another script. This is the morte() funcion (not all the script of lives):
public void morte()
{vite -= 1;
dead = true;
if (vite != 0)
Instantiate (o$$anonymous$$ide, currentspawn, Quaternion.identity);
else
GameObject.Find ("$$anonymous$$ain Camera").GetComponent<gameover> ().active = true;
}
Check your particle system component to ensure there is not a delay prior to spawning. (I think this option is in the first sub-menu). Nothing here would create a delay.
Answer by xDevily · Nov 02, 2014 at 04:25 PM
I found a solution. I move the particle system when needed whit this code: using UnityEngine; using System.Collections;
public class collisione : MonoBehaviour {
public GameObject blood;
void Start()
{blood=GameObject.Find("sangue");
}
void OnCollisionEnter2D (Collision2D coll)
{if (coll.gameObject.tag == "triangolo") {
blood.transform.position=this.gameObject.transform.position;
blood.particleSystem.Emit(100);
GameObject.Find ("Main Camera").GetComponent<lives>().morte();
Destroy (this.gameObject);
}
}
}
With this the particle sistem plays into the right position. Note: the gameobject is not a child of my character
Your answer
![](https://koobas.hobune.stream/wayback/20220613170448im_/https://answers.unity.com/themes/thub/images/avi.jpg)