首页 > 解决方案 > 动画剪辑错误

问题描述

我的动画脚本中的 Unity3D 有这些错误:

Assets\Assets\Scripts\Assembly-CSharp\AnimBg.cs(14,51): error CS7036: There is no argument given that corresponds to the required formal parameter 'clip' of 'AnimationClipPlayable.Create(PlayableGraph, AnimationClip)'

Assets\Assets\Scripts\Assembly-CSharp\AnimBg.cs(15,5): error CS1061: 'AnimationClipPlayable' does not contain a definition for 'speed' and no accessible extension method 'speed' accepting a first argument of type 'AnimationClipPlayable' could be found (are you missing a using directive or an assembly reference?)

Assets\Assets\Scripts\Assembly-CSharp\AnimBg.cs(16,38): error CS1503: Argument 1: cannot convert from 'UnityEngine.Animations.AnimationClipPlayable' to 'string'

代码如下所示:

using System;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Animations;

// Token: 0x02000002 RID: 2
[RequireComponent(typeof(Animator))]
public class AnimBg : MonoBehaviour
{
AnimationClipPlayable playable;
    // Token: 0x06000002 RID: 2 RVA: 0x00002058 File Offset: 0x00000458
    private void Start()
    {
        AnimationClipPlayable b = AnimationClipPlayable.Create(this.clip);
        b.speed = this.animspeed;
        base.GetComponent<Animator>().Play(b);
    }

    // Token: 0x04000001 RID: 1
    [SerializeField]
    private AnimationClip clip;

    // Token: 0x04000002 RID: 2
    [SerializeField]
    private float animspeed;
}

感谢您的帮助,因为我无法编译游戏并且我不知道如何解决这些错误。

标签: c#unity3d

解决方案


这个问题是这里的行

AnimationClipPlayable b = AnimationClipPlayable.Create(this.clip);

AnimationClipPlayable.Create 接受两个参数;一个可播放的图表和一个剪辑。您的剪辑是第二个参数,但您需要通过可播放图表作为第一个参数。

是 Unity Doc 来解释该功能的含义。

其次,AnimationClipPlayable 不包含名为 speed 的变量。如果您想修改剪辑速度,您应该使用SetSpeed()函数。

b.SetSpeed(animspeed);

第三,Animator 不包含名为 Play() 的覆盖函数,它接受一种 PlayableGraph。

很难知道你真正想要什么,但如果你只想在那个游戏对象上播放动画,你可以这样做:

using System;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Animations;

// Token: 0x02000002 RID: 2
[RequireComponent(typeof(Animator))]
public class AnimBg : MonoBehaviour
{
    // Token: 0x04000001 RID: 1
    [SerializeField]
    private AnimationClip clip;

    // Token: 0x04000002 RID: 2
    [SerializeField]
    private float animspeed;

    private PlayableGraph graph;
    private AnimationClipPlayable playable;
    private AnimationMixerPlayable mixer;
    // Token: 0x06000002 RID: 2 RVA: 0x00002058 File Offset: 0x00000458
    private void Start()
    {
        graph = PlayableGraph.Create();
        AnimationClipPlayable b = AnimationClipPlayable.Create(graph, clip);
        b.SetSpeed(animspeed);

        mixer = AnimationMixerPlayable.Create (graph);
        mixer.ConnectInput (0, b, 0);
        mixer.SetInputWeight (0, 1);

        var output = AnimationPlayableOutput.Create (graph, "output", GetComponent<Animator> ());
        output.SetSourcePlayable (mixer);
        graph.Play ();
    }
}

推荐阅读