- Home /
Length of Animation from Animator
I have an animation which plays once, and it played once just fine. I want to Invoke a method as soon as the animation finishes. I have been researching and experimenting for over an hour now, but without the result I want. I try to get the animation from the Animator, but Unity says my animation is not attached. The thing is, I don't care if it's attached...I just want to know how long it is, not actually do anything with it. How can I achieve this? Here is the code which results in the error:
CODE:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(PolygonCollider2D))]
[RequireComponent(typeof(Animator))]
public class Construction : MonoBehaviour
{
// Use this for initialization
void Start()
{
Invoke("EnableObstacleState", GetComponent<Animator>().animation.clip.length);
}
private void EnableObstacleState()
{
GetComponent<PolygonCollider2D>().enabled = true;
}
}
ERROR:
MissingComponentException: There is no 'Animation' attached to the "Barricade(Clone)" game object, but a script is trying to access it.
You probably need to add a Animation to the game object "Barricade(Clone)". Or your script needs to check if the component is attached before using it.
Construction.Start () (at Assets/Scripts/Construction.cs:11)
If the animation runs fine as it is, would using an animation event be a solution ins$$anonymous$$d of using Invoke?
Your answer
Follow this Question
Related Questions
2D Animation does not start 1 Answer
Mecanim: get animation duration from Animator state name 0 Answers
Check animator animation finished? 1 Answer
run animation when should idle 1 Answer
Create animation from script 0 Answers