Unity3d Animation (animation system) __unity3d

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 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.



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.