Good Afternoon fellow Devs,
I’m currently working on a Particle System in co-operation with the Ai that emit’s a particle upon the enemy’s death but just before the body is removed and re-spawned.
I’ve went ahead and looked for some tips online, however the issue am having here is that the references to gameobject.GetComponent in Unity 5 has changed and suggests I upgrade thus breaking the script.
Is there a better method to do this? Any tips or suggestions are extremely helpful.
My goal for this code is to perform the following functions in C#
- Player kills AI
- AI dies
- A particle emits around the AI upon death
- The particle stops
- AI’s body is removed from the game
- Re spawns.
I’ve got all except number 3 and 4 working, this is where I am having some trouble.
Code:
public class BloodBath : MonoBehaviour
{
//Name of Particle to emit
ParticleEmitter pe;
private bool isDead = false;
public float respawnTime = 10.0f;
void Start() {
ParticleEmitter pe = gameObject.GetComponent<ParticleEmitter> ().particleEmitter;
}
void Update() {
if (isDead)
{
//Play Particle upon Death
pe.emit = true;
respawnTime -= Time.deltaTime;
if (respawnTime <= 0.0f)
{
RemoveBody();
}
}
}
public void AIDead()
{
isDead = true;
}
void RemoveBody() {
Destroy(gameObject);
}
}
}