Unity3d's animation (animation system)

Source: Internet
Author: User

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 
  1. Using Unityengine;
  2. Using System.Collections;
  3. Public class Newbehaviourscript:monobehaviour {
  4. Animation M_anim;
  5. private float scalew = 1.0f; //Width scaling ratio
  6. private float Scaleh = 1.0f; //Height scaling ratio
  7. // Use this for initialization
  8. void Start () {
  9. //Get animation components
  10. M_anim = getcomponent<animation> ();
  11. if (!m_anim.isplaying)
  12. {
  13. //If no animation is played, the new Animation 1 animation is played by default
  14. M_anim.  Crossfade ("ation 1", 0.2f);
  15. }
  16. }
  17. //Update is called once per frame
  18. void Update () {
  19. Scalew = (float) screen.width/800; //Calculate width scaling ratio
  20. Scaleh = (float) screen.height/480; //Calculate height scaling ratio
  21. }
  22. void Ongui ()
  23. {
  24. GUI.skin.button.fontSize = (int) (* Scalew); //Adjust button font size
  25. if (GUI. button (new Rect (Scalew, Scaleh, 1 * scalew, + * Scaleh), "ation "))
  26. {
  27. M_anim.  Play ("ation 1");
  28. }
  29. if (GUI. button (new Rect (Scalew, Scaleh, * scalew, + * Scaleh), "Imation"))
  30. {
  31. M_anim.  Play ("Imation");
  32. }
  33. if (GUI. button (new Rect (Scalew, Scaleh *, * scalew, + * Scaleh), "over-playing ation 1" )
  34. {
  35. M_anim.  Crossfade ("ation 1", 0.5f);
  36. }
  37. if (GUI. button (new Rect (Scalew, Scaleh, +/-Scalew, + * Scaleh), "over-play imation" )
  38. {
  39. M_anim.  Crossfade ("Imation", 0.5f);
  40. }
  41. }
  42. }


Add code to the game object and run the game.

Unity3d's animation (animation system)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.