Here is the relevant code snippet:
public class AnimatedGameObject : MonoBehaviour
{
private float extentPlayed;
public AnimationClip Clip;
public GameObject AnimationTarget;
private void Update()
{
if (this.extentPlayed >= 1f)
{
return;
}
Debug.Log(this.extentPlayed);
this.Clip.SampleAnimation(this.AnimationTarget, extentPlayed * this.Clip.length);
this.extentPlayed += 0.005f;
}
}
In the Unity Editor, the game object assigned to AnimationTarget
contains the animator component controlled by the controller that uses Clip
.
However, when I start the game, even though I can see that this.extentPlayed
is being incremented every frame, no animation is taking place that I can see.
I am aware that what I am currently trying to do in the Update()
method can be achieved by calling SetBool(string name, bool value)
on the animator, but the purpose of writing the Update()
method this way is to gain familiarity with how the SampleAnimation()
method works, so that I can perform more complicated manipulations when necessary.
What changes should I make for the animation to take place?