🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

I don't understand how to switch animations in Unity. I use c#

Started by
1 comment, last by rogerdv 9 years, 1 month ago
public class BeamAnimScriptffs : MonoBehaviour {
public Animator extend;
// Use this for initialization
void Start () {
GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if (Input.GetButton ("fire3")){
Animation.Play(extend);
}
}
}
I get this error:
Assets/beam/BeamAnimScriptffs.cs(18,35): error CS0120: An object reference is required to access non-static member `UnityEngine.Animation.Play()'
I've looked around for a long time, and can't seem to get it right. I've switched around the code for about five hours now, as I read old topics on various sites linked by Google... I think it's time to get some help. I need to understand how it works.
Basically, I have an imported object with two animations in it inside the Animator, both made from Unity's built-in Animation window. Its default animation plays right, but I can't figure out how to change it when a button is pressed. It's a very simple animation (not even a skeleton) mostly meant to learn how to do it.
What am I doing wrong and how do I do it right?
Advertisement

It looks like you are using the old animation system instead of Mecanim, was that your intention?



There are a few tutorials that illustrate the use of mecanim, they are easy to underestand, even for newbies. The process involves creating an animation controller, and adding the animations. Then you set up the transitions between animations and variables. By setting a value in that variable, the animation controller triggers the corresponding transition from one animation to another.

This topic is closed to new replies.

Advertisement