void Start() { Animator anim = GetComponent(); anim.Play("Move", -1, 0f); }
void Start() { Animator anim = GetComponentIn both examples, the Animator component is used to play the animation. This component handles the timing, blending, and transitioning between animations. The AnimationClip is a container for the keyframes and curves that define the animation. The AnimationCurve is used to define the values of the animation at different points in time. The AnimationEvent is used to trigger a function at a specific point in the animation. Overall, Animator is a powerful package library in C# that allows developers to create complex animations with ease.(); AnimationClip clip = new AnimationClip(); clip.legacy = true; AnimationCurve scaleCurveX = AnimationCurve.Linear(0f, 1f, 1f, 2f); AnimationCurve rotationCurveY = AnimationCurve.EaseInOut(0f, 0f, 1f, 360f); AnimationCurve positionCurveZ = AnimationCurve.EaseInOut(0f, 0f, 1f, 10f); AnimationEvent evt = new AnimationEvent(); evt.time = 0.5f; evt.functionName = "HitTarget"; AnimationClipInfoProperties clipInfo = AnimationUtility.GetAnimationClipInfoProperties(clip); clipInfo.AddCurve("transform", typeof(Transform), "localScale.x", scaleCurveX); clipInfo.AddCurve("transform", typeof(Transform), "localRotation.eulerAngles.y", rotationCurveY); clipInfo.AddCurve("transform", typeof(Transform), "localPosition.z", positionCurveZ); clip.AddEvent(evt); anim.Play(clip.name); } void HitTarget() { Debug.Log("Hit the target!"); }