Я создаю Animator OverrideController через скрипт на основе текущего контроллера, назначенного компоненту аниматора.Я создал анимацию кривой для позиции, и она работает.Когда я пытаюсь оживить прозрачность (альфа-цвет материала), это не работает.Я не смог правильно получить доступ к этому свойству?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AnimationScript : MonoBehaviour {
void Start()
{
AnimationClip clip = new AnimationClip();
AnimationCurve curve = AnimationCurve.EaseInOut(0.0f, transform.position.x, 1.0f, transform.position.x);
clip.SetCurve("", typeof(Transform), "localPosition.x", curve);
curve = AnimationCurve.Linear(0.0f, 1.0f, 1.0f, 0.0f);
clip.SetCurve("", typeof(Material), "_Color.a", curve);
Animator anim = GetComponent<Animator>();
AnimatorOverrideController animatorOverrideController = new AnimatorOverrideController(anim.runtimeAnimatorController);
// "loop" is the name of clip not name of state
animatorOverrideController["loop"] = clip;
anim.runtimeAnimatorController = animatorOverrideController;
}
}
Однако работает аналогичный код для устаревшего компонента Animation:
void Start()
{
Animation anim = GetComponent<Animation>();
AnimationCurve curve;
// create a new AnimationClip
AnimationClip clip = new AnimationClip();
clip.legacy = true;
// update the clip to a change color
curve = AnimationCurve.Linear(0.0f, 1.0f, 2.0f, 0.0f);
clip.SetCurve("", typeof(Material), "_Color.a", curve);
// now animate the GameObject
anim.AddClip(clip, clip.name);
anim.Play(clip.name);
}
Что мне не хватает и почему не работает первый скрипт?