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 animated file
Select Legacy Property
Select the game object to open the Animation edit window
Add animation change Properties
attribute values that need to be changed for keyframes
Animation effect when configuration is complete
2, Code control animation
Play ("ation 1");, playing animation, passing parameters to animated name
Stop ("ation 1"), stop animation, pass parameters to animated name
Crossfade ("ation 1", 0.5f); , there are excessive toggle animations, incoming parameters (animated name, over time)
Instance Code
Using Unityengine;
Using System.Collections;
public class Newbehaviourscript:monobehaviour {Animation M_anim; private float Scalew = 1.0f; Width scaling than private float Scaleh = 1.0f; Height scaling ratio//Use this for initialization void Start () {//Get animation component M_anim = Getcomponent<animation> ()
; if (!m_anim.isplaying) {//If no animation is played, the new Animation 1 animation M_anim is played by default.
Crossfade ("ation 1", 0.2f); }//update is called once per frame void Update () {Scalew = (float) screen.width/800; Compute width Scaling ratio scaleh = (float) screen.height/480; Compute height Scaling} void Ongui () {GUI.skin.button.fontSize = (int) (* Scalew); Adjusts the button font size if (GUI). button (new Rect (Scalew, Scaleh, Scalew, Scaleh), "ation 1")) {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, 170 * Scaleh, Scalew * Scaleh, ation), "Play over 1") {M_anim.
Crossfade ("ation 1", 0.5f); } if (GUI. button (new Rect (Scalew, 230 * Scaleh, Scalew * Scaleh, Imation), "excessive playback") {M_anim.
Crossfade ("Imation", 0.5f);
}
}
}
Add code to the game object and run the game.