- Home /
Question by
DevBoiHayden · Nov 27, 2021 at 05:05 PM ·
particle system
How do i get my explosion particle system to play where ever the enemy is when it dies rather than at a set position?,Hey how do i have my explosion play on the enemy wherever the enemy is?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Enemy : MonoBehaviour { public float health = 50f;
public ParticleSystem explosion;
public void TakeDamage(float amount)
{
health -= amount;
if (health <= 0f)
{
EnemyDeath();
}
}
void EnemyDeath()
{
explosion.Play();
Debug.Log("exploded!");
Destroy(gameObject);
Debug.Log("Enemy Dead!");
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
,CURRENT CODE: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Enemy : MonoBehaviour { public float health = 50f;
public ParticleSystem explosion;
public void TakeDamage(float amount)
{
health -= amount;
if (health <= 0f)
{
EnemyDeath();
}
}
void EnemyDeath()
{
explosion.Play();
Debug.Log("exploded!");
Destroy(gameObject);
Debug.Log("Enemy Dead!");
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
Comment
Answer by sacredgeometry · Nov 27, 2021 at 05:28 PM
Use the enemies position as the emitters position