赞
踩
使用Unity自带的Animation制作的动画如何指定帧播放和结束?
1.选择需要播放的动画,Inspector面板右键Debug,勾选Legacy
2.添加脚本,挂载脚本
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class AnimationTest : MonoBehaviour { public Animation _animation; [Tooltip("哪一帧开始")] public int startFrame; [Tooltip("哪一帧结束")] public int endFrame; [Tooltip("动画名字")] public string aniName; private float starttime; // Use this for initialization void Start () { _animation = gameObject.GetComponent<Animation>(); //_animation[aniName].time = startFrame / _animation[aniName].clip.frameRate; _animation[aniName].time = (float)startFrame / 60; PlayAnimation(_animation, aniName, (float)endFrame/60, () => { Debug.Log("开始播放"); }, () => { Debug.Log("动画暂停"); }); } // Update is called once per frame void Update () { } public void PlayAnimation(Animation ani, string clipname, float time, Action startAct = null,Action tempAct=null) { StartCoroutine(PlayAnimationItor(ani, clipname, startAct, time, tempAct)); } IEnumerator PlayAnimationItor(Animation ani, string clipname, Action startAct, float time, Action tempAct) { startAct?.Invoke(); ani.Play(clipname); yield return new WaitForSeconds(time); ani.Stop(); tempAct?.Invoke(); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。