Question by
unity_UD0pZx_qONdGCw · Apr 18, 2021 at 01:04 PM ·
collisiongameobjectplayerparticlesystemdeath
Make a Particle System play when Player gets destroyed
So the title says everything but heres some details : My players name is "Player" and i have an enemyobject script called "OnCollisionDestroy" that has "OnCollisionEnter(Collision other)" on it so it makes my Player destroy when the enemy hits my Player. The thing i want is that at the same time the Player gets destroyed the particle system plays. The particle systems name is "Deatheffect". Any help is appreciated!!!!
This is my current OnCollisionDestroy script (the code that makes my Player get destroyed on touch with the enemy) :
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class OnCollisionDestroy : MonoBehaviour {
void OnCollisionEnter(Collision other)
{
if(other.gameObject.tag == "Enemy")
{
//Instantiate our one-off particle system
ParticleSystem DeathEffect = Instantiate(DeathEffect)
as ParticleSystem;
DeathEffect.transform.position = transform.position;
//play it
DeathEffect.loop = false;
DeathEffect.Play();
Destroy(DeathEffect.gameObject, DeathEffect.duration);
Destroy(gameObject);
}
}
}
Comment