鸟语天空
Animation
post by:追风剑情 2015-12-25 11:51

一、工程结构

p1.png

p2.png

p3.png

1.png

 

二、创建AnimationTest.cs脚本并挂在箭塔上

using UnityEngine;
using System.Collections;

public class AnimationTest : MonoBehaviour {

    public Animation animation;

	void Start () {
        if (null == animation)
            animation = GetComponent<Animation>();

        //从Resources文件夹动态加载另外两个动画剪辑
        AnimationClip jianta_ani_open = Resources.Load("jianta_ani_open") as AnimationClip;
        AnimationClip jianta_ani_close = Resources.Load("jianta_ani_close") as AnimationClip;
        animation.AddClip(jianta_ani_open, "open");
        animation.AddClip(jianta_ani_close, "close");
	}

    void OnGUI()
    {
        if (GUILayout.Button("Play open"))
        {
            animation.CrossFade("open");
        }

        if (GUILayout.Button("Play close"))
        {
            animation.CrossFade("close");
        }

        if (GUILayout.Button("Take 001"))
        {
            animation.CrossFade("Take 001");
        }
	}
}

运行效果

r1.png

r2.png

 

 

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容