Animation

作者:追风剑情 发布于:2015-12-25 11:51 分类:Unity3d

一、工程结构

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

 

 

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号