Starting particle system when animation plays
Hi,
I have an animated GameObject with a particle system as a child . I need to play the particle system only once the animation is playing. The animation only runs once, then the particles need to stop. Is there any easy way to control this?
Answer by Headrush95 · Mar 30 at 11:30 PM
use this to get information about current animation clip : https://docs.unity3d.com/ScriptReference/Animator.GetCurrentAnimatorClipInfo.html
private string _CurrentClipName;
public Animator animator;
private AnimatorClipInfo[] _CurrentAnimationClipInfo;
private float _CurrentClipLength;
private String _CurrentClipName;
public bool Instanced = false;
// create a prefab with your partcles on the prefab object
public Gameobject instantiateParticleObject;
private Gameobject TempInstantiateParticleObject;
void Update()
{
_CurrentAnimationClipInfo =animator.GetCurrentAnimatorClipInfo(0);
_CurrentClipName = _CurrentAnimationClipInfo[0].clip.name;
_CurrentClipLength = _CurrentAnimationClipInfo[0].clip.length;
}
void CheckAnimation()
{
if (_CurrentClipName == "Slam" && !Instanced)
{
Vector3 CurrentPosition = this.transform.position;
TempInstantiateParticleObject =
Instantiate(instantiateParticleObjcect, CurrentPosition, Quaternion.identity);
Instanced = true;
//cooldown here
}
if (_CurrentClipName != "Slam")
{
Instanced = false;
}
}
void OnGUI()
{
//Output the current Animation name and length to the screen
GUI.Label(new Rect(0, 0, 200, 20), "Clip Name : " + _CurrentClipName);
GUI.Label(new Rect(0, 30, 200, 20), "Clip Length : " + _CurrentClipLength);
}
you will need to add your (play particle and destroy().this) script to the particle object prefab but all this should help you get started
Your answer

Follow this Question
Related Questions
setting a particle system to overwrite old particles, to make way for the new? 1 Answer
How can I rapidly trigger the same particle system? 2 Answers
Particle System is behind Background Image (2D) 4 Answers
Fade particle emission rate over time 0 Answers
I am having trouble getting these effects to work on Android! Can someone please help me? 0 Answers