用到的资源:GitHub - unity3d-jp/unitychan-crs: Unity-Chan "Candy Rock Star" Live Demo
这边直接在他提供的Scene上修改
Playable API来播放Animation Clip的脚本:
using UnityEngine; using UnityEngine.Animations; using UnityEngine.Playables; public class PlayAnimClip : MonoBehaviour { public AnimationClip animClip; private PlayableGraph _graph; private AnimationClipPlayable _animClipPlayable; void Start() { _graph = PlayableGraph.Create("ChanPlayableGraph"); var animationOutputPlayable = AnimationPlayableOutput.Create(_graph, "AnimationOutput", GetComponent<Animator>()); //往graph添加output _animClipPlayable = AnimationClipPlayable.Create(_graph, animClip); //往graph添加playable animationOutputPlayable.SetSourcePlayable(_animClipPlayable); _graph.Play(); } void Update() { if (Input.GetKeyDown(KeyCode.Alpha1)) { _animClipPlayable.SetTime(0); } } }
把本来的几个脚本都关掉,添加上面的PlayAnimClip脚本,再把向前跑动画绑定上去
运行效果:按1的时候从头开始播放
看下PlayableGraph的可视化图形:
标签:UnityEngine,Clip,PlayableGraph,graph,Create,API,Playable,animClipPlayable,Animat From: https://www.cnblogs.com/sailJs/p/16989878.html