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?

If I understand correctly what you are trying to achieve, simply open the animation file that is controlling the game object and keyframe the particle system emission / activation there. No need to overcomplicate this with a script.

use this to get information about current animation clip : Unity - Scripting API: Animator.GetCurrentAnimatorClipInfo

 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