I'm making a first person shooter game and got the movement and the gun script to work but I created an particle system for when my enemy dies it will play, but when my character dies it doesn't play and I've tried searching and trying but none of them worked?
Code:
using UnityEngine;
public class EnemyMovement : MonoBehaviour
{
public float MaxHealth = 100;
public HealthBarScript healthBar;
public ParticleSystem EnemyDeath;
public void TakeDamage(float Amount)
{
MaxHealth -= Amount;
if (MaxHealth <= 0)
{
EnemyDeath.Play();
Die();
}
void Die()
{
Destroy(gameObject);
}
}
// Update is called once per frame
void Update()
{
}
}
CodePudding user response:
It is playing, but because you destroy the gameobject right after the particle effect is played, it last only a fraction of the second.
You would have to create the particle effect on different object, not on the object that is being destroyed. Ideally there should be separate Particle Effect Manager, which will store and play all the particle effects when called.