Unable to play animation on instantiated prefab

Hi,
I have an animation clip on a prefab, specifically I’m animating the alpha channel on the GameObject to make it fade in when it is instantiated. The GameObject ("DustCloud ") instantiates fine but no animations can be called on it. My code is kind of a mangled mess of different attempts at this point. Any advice about an approach would be great. The animation has been marked legacy.

   if (other.CompareTag("Player"))
        {
            Instantiate(DustCloud, PlayerCam.transform.position, PlayerCam.transform.rotation);
            DustCloud.GetComponent<Animation>().Play("DustUp");
            //DustCloud = (GameObject)Instantiate(gameCharacterPrefab, PlayerCam.transform.position,                            Quaternion.identity);
            Debug.Log("DustCloud");
            //anim = DustCloud.GetComponent<Animator>();
            //anim.Play("DustUp");
         }

Maybe it should be

DustCloud.GetComponent<Animator>().Play("DustUp");
1 Like

Thanks for the reply. I’ll give it a try.