是的,但不是。
这里的“是”是指您可以拨打一系列电话来获取数据并进行修改,
但是
仅允许作为编辑器脚本进行修改:不能在运行时播放器环境中修改值。
参见文档:
https://docs.unity3d.com/ScriptReference/AnimationClip.SetCurve.html
注意:SetCurve仅在运行时适用于传统动画剪辑。对于非传统AnimationClips,它是一个仅用于编辑器的功能。
下面的脚本示例显示了如何使用动画片段为游戏对象位置设置动画。使用SetCurve()将动画曲线设置到AnimationClip上。此示例将x偏移从1.0向下移动到0.0。
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Animation))]
public class ExampleClass : MonoBehaviour {
public Animation anim;
void Start() {
anim = GetComponent<Animation>();
AnimationCurve curve = AnimationCurve.Linear(0.0F, 1.0F, 2.0F, 0.0F);
AnimationClip clip = new AnimationClip();
clip.legacy = true;
clip.SetCurve("", typeof(Transform), "localPosition.x", curve);
anim.AddClip(clip, "test");
anim.Play("test");
}
}