使用Unity自带的Animation制作的动画如何指定帧播放和结束?
1.选择需要播放的动画,Inspector面板右键Debug,勾选Legacy
2.添加脚本,挂载脚本文章来源地址https://www.toymoban.com/news/detail-771446.html
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();
}
}
总结
文章来源:https://www.toymoban.com/news/detail-771446.html
到了这里,关于Unity中Animation创建的动画如何指定播放的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!