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();
}
}
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);
}