c# - 动画剪辑错误
问题描述
我的动画脚本中的 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;
}
感谢您的帮助,因为我无法编译游戏并且我不知道如何解决这些错误。
解决方案
这个问题是这里的行
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 ();
}
}
推荐阅读
- python - 有没有办法让 if 语句知道我的输入是一个数字?
- pandas - 列的划分没有返回正确的值
- postgresql - 递归查询引用匹配条件的最后一行
- javascript - 有没有办法在 TypeScript 中动态应用数组映射器?
- c++ - 用于创建类生成线程的多个实例的 C++ 线程模型
- python - 如何在 Python/Ansible 中用模式 {{ '{{' }} / {{ '}}' }} 替换大括号 {{ }}
- actions-on-google - Google 上的操作部署发布挂起
- vue.js - Vuex 未知动作类型:getProducts
- sql - 使用 INNER JOIN 的动态 SQL 查询
- powershell - 尝试运行 DISM 在线命令以从已安装的驱动器安装驱动程序时出错