- Home /
How do I make particles play on trigger
I've tried alot of scripts and tutorials but nothing will work I can't get the death particles to play when my player dies so can someone please help me solve my problem. Here's my script
public class youdead : MonoBehaviour { public ParticleSystem part;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter2D()
{
Destroy (this.gameObject);
part.Play();
}
}
Answer by HellsHand · Apr 12, 2021 at 11:26 PM
From your script the reason your part.Play();
doesn't work is because there is no script to call it, your script ends at Destroy(this.gameObject);
. You would either need to call it from another script or wait for it to play before destroying your game object. A very basic way to do this is:
void OnTriggerEnter2D()
{
part.Play();
StartCoroutine(KillPlayer());
}
IEnumerator KillPlayer()
{
yield return new WaitForSeconds(seconds); //seconds being how long the particle plays for
Destroy(this.gameObject);
}
Your answer

Follow this Question
Related Questions
how do you make a 3d person or object? 2 Answers
SQLite in Unity 4.x? 0 Answers
how to open probuilder basic 1 Answer
Can't create a new shader 1 Answer
How to make atmospheric dust particles? 4 Answers