C# 如何在不使用animator的情况下获得实际的动画播放位置?
如果达到这个位置,动画应该重新开始。有什么想法吗?如何使用C#脚本实现这一点?我没有使用任何动画师,只是在ChildObject中使用动画。 这当然行不通,因为它总是正确的:C# 如何在不使用animator的情况下获得实际的动画播放位置?,c#,unity3d,scripting,C#,Unity3d,Scripting,如果达到这个位置,动画应该重新开始。有什么想法吗?如何使用C#脚本实现这一点?我没有使用任何动画师,只是在ChildObject中使用动画。 这当然行不通,因为它总是正确的: 45 看起来就像是你想在动画结束时触发重启。因此,在动画末尾插入AnimationEvent。看看Unity的简单脚本API示例。忽略这样一个事实,他们使用的是动画师,他们只是使用它来获得剪辑。显然,你已经有了你的剪辑 这是上面链接中修改的Unity脚本 if(length==45) anim.Restart();
45
看起来就像是你想在动画结束时触发重启。因此,在动画末尾插入AnimationEvent。看看Unity的简单脚本API示例。忽略这样一个事实,他们使用的是动画师,他们只是使用它来获得剪辑。显然,你已经有了你的剪辑 这是上面链接中修改的Unity脚本
if(length==45)
anim.Restart();
伟大的因为你的努力给了你声誉分数。我没有使用AnimationClip,我只是在使用动画。有什么不同?谢谢。只是查了一下。以前从未使用过它-显然
动画
是执行动画的传统方式。Unity在不久前切换到了一个AnimationClip
/Animator
耦合。如果可以,请尝试切换到使用AnimationClip
。这很容易,特别是当你使用1个动画的时候。如果你混合了不止一个,看起来会更困难。不过,我以前从未用过它。
if(length==45)
anim.Restart();
public void Start()
{
// existing components on the GameObject
AnimationClip clip;
// new event created
AnimationEvent evt;
evt = new AnimationEvent();
// put some parameters on the AnimationEvent
// - call the function called PrintEvent()
// - the animation on this object lasts 2 seconds
// and the new animation created here is
// set up to happen 1.3s into the animation
evt.intParameter = 12345;
evt.time = 1.3f;
evt.functionName = "PrintEvent";
clip.AddEvent(evt);
}
// the function to be called as an event
public void PrintEvent(int i)
{
print("PrintEvent: " + i + " called at: " + Time.time);
}