Playing animation at the start

The animation plays at the start however when i leave the scene and come back, the animation does not play. It’s marked as legacy and i’ve tried to use code:

public GameObject The_Cam;

void Start()
{
	Screen.SetResolution (1920, 1080, true);
	The_Cam.GetComponent<Animation>().Play();

}

ignore the Screen.SetResolution (1920, 1080);

I’be used the animator component and used the animation component but both does not work.

The animation is on a camera

1 Answer

1

The Animation component has a default animation slot. Make sure the animation you want to play is assigned to it.
You can also try this :

Debug.Log ( The_Cam.GetComponent<Animation>().Play() );

If it returns false, it means there’s no default animation to be played.

You can also force it to play the animation, passing the animation name, like :

The_Cam.GetComponent<Animation>().Play("AnimationName");

And if you were to use Animator instead, which I would recommend, you pass it the name of the state (not the animation). The_Cam.GetComponent<Animator>().Play("StateName");

I've tried the two above and both don't work. The top one comes as True but still doesn't play the animation and the second does nothing for some reason. I've tried the last one with the animator and does not work for some reason.