Hey so I’m trying to do this thing where you can open a door by spinning a crank. Now, I made the crank object in Maya and made the animation in unity. using UnityEngine;
using System.Collections;
public class Crank : MonoBehaviour {
public bool inRange = false;
//public AnimationClip crankspin;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (inRange == true && Input.GetKeyDown(KeyCode.F)){
animation.wrapMode = WrapMode.Once;
animation.Play("crank spin");
}
}
}
So the inRange bool is made true in a another script, and I know that works. But when I try and press F and make the crank animate, unity gives me this error
“The animation state crank spin could not be played because it couldn’t be found!
Please attach an animation clip with the name ‘crank spin’ or call this function only for existing animations.
UnityEngine.Animation:Play(String)
Crank:Update() (at Assets/scripts/Crank.cs:17)”
People have told me to set the model to a legacy rig, which I have already done. I drag and dropped the animation onto the object along with the script, but Unity just can’t find it!
Help?
Just read [this blog post of Eric Lippert][1]. Note that Eric is one of those who developed and designed the C# compiler for Microsoft. Also note that "C# 5" doesn't apply to Unity / Mono in general. This is a quite common problem and got asked several times before, [see my answer over here][2]. [1]: https://blogs.msdn.microsoft.com/ericlippert/2009/11/12/closing-over-the-loop-variable-considered-harmful/ [2]: http://answers.unity3d.com/answers/1195941/view.html
– Bunny83