简体   繁体   English

动画状态..因为找不到而无法播放?

[英]The animation state .. could not be played because it couldn't be found?

I am trying to start an animation by pressing a key on my keyboard.我正在尝试通过按键盘上的键来启动动画。

For this I am using the following code:为此,我使用以下代码:

[HideInInspector] public Animation animation;

private void Start()
{
    animation = GetComponent<Animation>();
}

private void Update()
{
    if (Input.GetKeyDown("1"))
    {
        animation.Play("AnimationName");
    }
}

This gives me the following error:这给了我以下错误:

The animation state AnimationName could not be played because it couldn't be found!动画状态 AnimationName 无法播放,因为找不到!

Although, the animation DOES start, but how can I clear this error?虽然,动画确实开始了,但我怎样才能清除这个错误?

I think the only possible explaination is that your animation clip is not marked as Legacy. 我认为唯一可能的解释是您的动画剪辑未标记为“旧版”。 https://www.unity3dtips.com/zh/the-animation-state-could-not-be-played-because-it-couldnt-be-found/ https://www.unity3dtips.com/zh/the-animation-state-could-not-be-played-cause-it-couldnt-be-found/

EDIT with step by step here: 在这里逐步进行编辑:

Animations must be marked as legacy to be used with the animation component. 动画必须标记为旧版才能与动画组件一起使用。

  1. In the project window select the animation clips you're trying to play. 在项目窗口中,选择要播放的动画剪辑。

  2. Set the inspector to debug mode which exposes hidden variables, in this case it'll make the “Legacy” checkbox appear.Unity Inspector Debug Mode 将检查器设置为暴露隐藏变量的调试模式,在这种情况下,它将使“传统”复选框出现。UnityInspector Debug Mode

  3. Tick the “Legacy” checkbox and change the inspector back to normal mode. 勾选“旧版”复选框,然后将检查器更改回普通模式。 Unity Inspector Animation Clip Legacy Checkbox Unity Inspector Animation Clip Legacy复选框


But there is one thing you should know: you should avoid, if possible, the old legacy way to play animation. 但是您应该知道一件事:如果可能,应该避免使用旧的传统动画播放方式。 Learn how to use an Animator component. 了解如何使用Animator组件。 Just create an animator, assign your animation clip, decide a boolean for start the animation in the animator component and set it to true in your code (for basic use). 只需创建一个动画师,分配动画剪辑,在动画师组件中确定一个用于启动动画的布尔值,然后在代码中将其设置为true(用于基本用途)即可。 Sure there is some things to do beside code but it will be easier to control your animation, bleand different animations and change them to your needs (it's for example much easier to loop or stop the animation at some point). 当然,在代码旁边还有一些事情要做,但是控制动画,对不同动画进行漂白和根据需要更改它们会更容易(例如,在某个时候循环或停止动画要容易得多)。 It would be also easier to understand when it start and when is playing. 当它开始播放和播放时,也将更容易理解。

Another thing to check is the legacy 'Animation' component on your gameObject that is supposed to perform the animation.要检查的另一件事是应该执行动画的游戏对象上的旧版“动画”组件。 In my case things were marked as legacy for the animation on the imported animation but somehow when adjusting settings on my import it dropped the animation it was complaining about from the actual 'Animation' component so once I added it things worked as expected在我的情况下,导入动画上的动画被标记为遗留,但不知何故,在调整我的导入设置时,它从实际的“动画”组件中删除了它抱怨的动画,所以一旦我添加它,事情就会按预期工作

Inspector in Debug mode showed my animation marked as 'Legacy' true调试模式下的检查器显示我的动画标记为“旧版”真在此处输入图像描述

My Animation component showed the missing animation我的动画组件显示缺少的动画在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM