- Home /
Emit Particle upon Death
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);
}
}
}
It is called ParticleSystem now. As of 4.3 and later I think.
Answer by Bioinformatizer · Jun 08, 2015 at 09:33 PM
A good way to do this is to create an empty GameObject, attach the particle emitter to it, and store it as a prefab in your assets folder.
If you make a 'public GameObject prefabPe' in your current script in place of the 'ParticleEmitter pe', you can then move the prefab from your assets folder onto this script in the unity window.
You call instantiate on that asset like 'pe = Instantiate(prefabPe, gameObject.transform.postition, gameObject.transform.rotation);'
Then call 'Destroy(prefabPe, timeToWait);' Simple Enough Huh? Good Luck!
Ps. you do not need that getComponent with this method, so that can all go.
Thank you, this worked however just for future reference it worked just by using Instantiate ins$$anonymous$$d of pe = Instantiate and position had a small typo. But thank you none the less.
Answer by Stoyanow · Jun 08, 2015 at 09:27 PM
https://www.youtube.com/watch?v=vwUahWrY9Jg∈dex=5&list=PLiyfvmtjWC_Up8XNvM3OSqgbJoMQgHkVz
About the particles
https://www.youtube.com/watch?v=4vOyENoIyH4∈dex=11&list=PLiyfvmtjWC_Up8XNvM3OSqgbJoMQgHkVz
This might help you with the re-construction of the code.
Thank you, i found this video very useful and all systems are go!
Your answer
Follow this Question
Related Questions
Weeping Angel AI / OnTriggerStay Problems 1 Answer
Guides or Tutorials for a Very Basic Enemy AI? [Unity 5] 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers