- Home /
How Would I instantiate a particle system onto my obstacle on collision after it being destroyed?
I am trying to make the obstacle have an effect when it gets destroyed. I have made the particle system a prefab and it is already added to the obstacle. What I am asking is how to make the particle system be triggered and instantiated on the position of the obstacle after the obstacle being destroyed. I understand this situation but am still new to unity and programming.
Here's my code:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Target : MonoBehaviour { [SerializeField] ParticleSystem _particleSystem; public float obstacleHealth = 1.0f; void OnCollisionEnter2D(Collision2D other) { if(other.gameObject.name == "Player") { obstacleHealth = obstacleHealth - 1; } } private void Update() { if(obstacleHealth <= 0) { _particleSystem.Play(); Destroy(gameObject); } } }
,