Animation脚本

///***注:模型要设置类型为Legacy,否则动画不能播放


//Unity制作的单个动画播放
public class AnimationControl : MonoBehaviour { public Animation anim; public AnimationClip _anim; public Toggle BatteryTog; void Awake() { _anim.legacy = true; anim = GetComponent<Animation>(); anim["DCZ2"].speed = 0; } void Start() { EventTriggerListener.Get(BatteryTog.gameObject).onClick = PalyAnimation; } void PalyAnimation(GameObject game) { if (game.GetComponent<Toggle>().isOn) { anim["DCZ2"].normalizedTime = 0; anim["DCZ2"].speed = 1; anim.Play("DCZ2"); } else { anim["DCZ2"].speed = 0; } } }

  ///切割动画播放,动画中的每部分都挂载此脚本

using UnityEngine;
using System.Collections;

public class AnimationControl : MonoBehaviour
{
    public GameObject Game;
    public Animation _Anima;    
    public string animName;  

    void Start()
    {
        Debug.Log(animName);
    }
    void OnMouseDown()
    {
        PlayAnimation(animName);
    }

    void PlayAnimation(string str)
    {
        _Anima[str].speed = 1;
        _Anima[str].normalizedTime = 0;
        _Anima.Play(str);
        if (_Anima.IsPlaying(str) && _Anima[str].normalizedTime >= 1)
        {
            Game.SetActive(false);
        }
    }
}

 

posted @ 2017-06-20 10:46  CocomoNo1  阅读(315)  评论(0编辑  收藏  举报