如何从特殊帧开始动画

How to start animation from special frame

我是 Unity 新手。我使用的是最新版本的 Unity,5.1.2f1 Personal。

我想从特殊帧开始动画。不是从一开始。

所以我搜索并得到了这些答案;

http://answers.unity3d.com/questions/181903/jump-to-a-specific-frame-in-an-animation.html

http://answers.unity3d.com/questions/425985/set-the-current-time-frame-of-a-mecanim-animation.html

但是在我的项目中,它并没有起作用!我花了一段时间来解决这个问题。

情况是这样的。我正在制作洛克人 (洛克人) 游戏。

而且我必须实现角色零在坠落时使用他的军刀,

falling_shot 动画从帧开始。

观看这张图片以帮助您解释我必须做什么。

这是个简单的问题。如果我可以直接使用动画数组的索引访问每一帧,

我要做的就是将播放索引设置为下一帧的索引。不难。

但是在Unity中,我无法直接访问Animation组件

而且我发现我必须使用 operator this [] 之类的;

// set start frame with time 0.5
animation["JumpShotA"].time = 0.5f;

但是没有用。这是我播放动画“JumpShotAir”的代码。

不是改变动画帧的代码,而是播放JumpShotAir动画。

using UnityEngine;
using System.Collections;

public class ZController : MonoBehaviour {
    Animator _animator;

    // Use this for initialization
    void Start () {
        _animator = GetComponent<Animator>();
        var animation = GetComponent<Animation>();
        var jumpShotA = animation["JumpShotA"];
        animation.clip = jumpShotA.clip;
        animation.Play();
    }
    
    // Update is called once per frame
    void Update () {
    
    }
}

但是这段代码的结果是这样的; NullReferenceException 消息:GetRef 错误。

我真的不知道。我做错了什么?我的代码有问题吗?

我可以直接访问动画组件的数组吗?我怎样才能访问它?

如果你想下载我的测试项目,请查看这里。

Test project. Links to Google drive.

感谢阅读。


Unity window 图片已更新。请检查我的错误。


<iframe width="560" height="315" src="https://www.youtube.com/embed/gOzhNK6qjNQ" frameborder="0" allowfullscreen></iframe>

我将动画类型更改为旧版,但问题仍然存在...

确保 GameObject 的动画组件中的动画数组中存在 JumpShotA 剪辑。此错误表明您在尝试播放动画数组时没有对 JumpShotA 的引用。