昨天同事想控制一个角色射箭动画,在拉弓的时候想用代码控制人物拉弓的整个过程,查了一下API,方法很简单Animator.StartPlay()(http://wiki.ceeger.com/script:unityengine:classes:animator:animator.startplayback),使用Animator.StopPlayback()停止动画器播放模式。当播放停止时,Avatar恢复从游戏逻辑获得控制权
Example:
1 using UnityEngine; 2 using System.Collections; 3 4 public class AnimatorPlay_ts : MonoBehaviour { 5 6 public Animator animator; 7 8 [Range(0,3)] 9 public float PlayBackTime = 0; 10 11 bool startplayback = false; 12 13 void Start() { 14 animator.StartPlayback(); 15 startplayback = true; 16 17 } 18 19 } 20 void Update(){ 21 if (startplayback) 22 animator.playbackTime = PlayBackTime; 23 } 24 }
时间: 2024-10-30 04:14:41