Hi all! I want to use Animation to enable and disable the Mesh Renderer component after some time, and I want to write the script in Animation through code using AnimationUtility. During the animation playback, for some reason, the Mesh Renderer activation point is only highlighted in blue, but the component itself is not activated, and for some reason the Property itself also has no checkmarks during the animation playback. How to solve this problem?
Here is my code and screenshots of the problem:
void toDoAnimation(GameObject frame, AnimationClip animationClip, int currentFrame)
{
Animator animator = frame.GetComponent<Animator>();
if (animator == null)
{
animator = frame.AddComponent<Animator>();
}
EditorCurveBinding curveBinding = new EditorCurveBinding();
curveBinding.type = typeof(MeshRenderer);
curveBinding.path = GetGameObjectPath(frame.transform);
curveBinding.propertyName = "m_Enabled";
AnimationCurve curve = new AnimationCurve();
curve.AddKey(1.0f, 1.0f);
curve.AddKey(currentFrame / animationClip.frameRate, 1.0f);
AnimationUtility.SetEditorCurve(animationClip, curveBinding, curve);
}