- Home /
Why i can't play animation clip i did ? Tried anything so far.
I have unity version 5.5.1f1 Personal
What i want is when running the game that the animation clip will start playing automatically.
I added to the Main Camera a Animation component. Added in the Inspector to the Animation the clip file name Camera_Sign003 also set the Animations size to 1 and added there the same clip Camera_Sign003. Also i set to true the Play Automatically.
I also attached a script to the Main Camera:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraPoints : MonoBehaviour
{
public Animation anim;
IEnumerator Start()
{
anim = GetComponent<Animation>();
anim.Play(anim.clip.name);
yield return new WaitForSeconds(anim.clip.length);
}
}
I tried to change the script instead IEnumerator just void Start()....but also didn't work.
And i checked with a break point it's getting to the line anim.Play....And the length is 10 but nothing happen after 10 seconds.
The animation is a short clip moving the camera from point to point.
The Main Camera is child under ThirdPersonController.
I added to the Main Camera Animation component i tried to add also Animator component to the Main Camera set it to Apply Root Motion. I tried with or without the script attached to the Main Camera too. I tried on the Main Camera to check/uncheck the Batching Static. I checked the animation clip to be Legacy.
I'm out of any ideas. In the Animation window i can play the clip. But when running the game nothing.
Answer by BaldBeardedMonk · May 06, 2017 at 08:52 PM
Attach Animator component. and edit the animator to have your animation clip after the Entry state. This should make the animation play automatically without the need of any script. If you want to use the Animation component instead i believe the animation clip then has to be marked as 'legacy'. to mark it as legacy switch to "debug" mode in the inspector and check the legacy option
Ok i got to a point where i see it playing the animation in the Animator editor. You can see the blue bar in the Animator editor window on the Camera_sign003.
And the script: Now i'm using in the script the Animator component to play the Camera_Sign003 clip if i will not use the script it will play will try to play the Camera_Sign001.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraPoints : $$anonymous$$onoBehaviour
{
private Animator _anim;
private void Start()
{
_anim = GetComponent<Animator>();
_anim.CrossFade("Camera_Sign003", 0);
}
}
Any way it's not working. I'm not getting any errors or warnings about it but still the camera stay at the same play when running the game nothing change. I don't see the clip running when running the game.
In the screenshot it's the animator editor window of the $$anonymous$$ain Camera. So it seems like it's playing the file but not showing it.
The video clip already set to Legacy.