1, animation system configuration,2, code control animation
Original address: http://blog.csdn.net/dingkun520wy/article/details/51247487
1, Animation system configuration
Create the Game object and add the animation component, and then drag the animation file into the component.
Enter the debug properties panel of the animation file
Check the Legacy property
Select the Game object, open the Animation edit window
Add animation change Properties
To change the attribute value of a keyframe
Animate after configuration is complete
2, Code control animation
Play ("Ation 1"), play animation, pass in parameter as animated name
Stop ("ation 1"), stops the animation, passes in the parameter as the animated name
Crossfade ("ation 1", 0.5f); , there are over-switching animations, incoming parameters (animated name, over time)
Instance Code
[CSharp]View PlainCopy
- Using Unityengine;
- Using System.Collections;
- Public class Newbehaviourscript:monobehaviour {
- Animation M_anim;
- private float scalew = 1.0f; //Width scaling ratio
- private float Scaleh = 1.0f; //Height scaling ratio
- // Use this for initialization
- void Start () {
- //Get animation components
- M_anim = getcomponent<animation> ();
- if (!m_anim.isplaying)
- {
- //If no animation is played, the new Animation 1 animation is played by default
- M_anim. Crossfade ("ation 1", 0.2f);
- }
- }
- //Update is called once per frame
- void Update () {
- Scalew = (float) screen.width/800; //Calculate width scaling ratio
- Scaleh = (float) screen.height/480; //Calculate height scaling ratio
- }
- void Ongui ()
- {
- GUI.skin.button.fontSize = (int) (* Scalew); //Adjust button font size
- if (GUI. button (new Rect (Scalew, Scaleh, 1 * scalew, + * Scaleh), "ation "))
- {
- M_anim. Play ("ation 1");
- }
- if (GUI. button (new Rect (Scalew, Scaleh, * scalew, + * Scaleh), "Imation"))
- {
- M_anim. Play ("Imation");
- }
- if (GUI. button (new Rect (Scalew, Scaleh *, * scalew, + * Scaleh), "over-playing ation 1" )
- {
- M_anim. Crossfade ("ation 1", 0.5f);
- }
- if (GUI. button (new Rect (Scalew, Scaleh, +/-Scalew, + * Scaleh), "over-play imation" )
- {
- M_anim. Crossfade ("Imation", 0.5f);
- }
- }
- }
Add code to the game object and run the game.
Unity3d's animation (animation system)