Consider the following C# code snippet in Unity that plays an animation clip on an Animator component. What will be printed to the console?
using UnityEngine; public class PlayAnimation : MonoBehaviour { public Animator animator; void Start() { animator.Play("Jump"); Debug.Log(animator.GetCurrentAnimatorStateInfo(0).IsName("Jump")); } }
The animation state may not be updated immediately after calling Play.
Calling animator.Play("Jump") schedules the animation to play, but the state info is not updated until the next frame. So, IsName("Jump") returns false immediately after Play.
In Unity, you want to make an animation clip play twice as fast. Which property should you modify?
Think about what controls the overall speed of the Animator component.
The Animator component has a speed property that controls the playback speed of all animations it plays. Changing AnimationClip.length or frameRate does not affect playback speed at runtime.
Given this code snippet, the animation clip does not play on the GameObject. What is the cause?
using UnityEngine; public class AnimateObject : MonoBehaviour { public AnimationClip clip; private Animation animationComponent; void Start() { animationComponent = GetComponent<Animation>(); animationComponent.AddClip(clip, "run"); animationComponent.Play("run"); } }
Check if the required component exists on the GameObject.
The code calls GetComponent<Animation>(), but if the GameObject does not have an Animation component attached, animationComponent will be null and calling AddClip or Play will fail silently or cause errors.
Which code snippet correctly creates a new AnimationClip and plays it on an Animation component at runtime?
Remember the signatures of AddClip and Play methods.
AddClip requires the clip and a string name. Play requires the string name of the clip to play. Passing the clip object directly to Play is invalid.
You want to blend between two animation clips "Walk" and "Run" smoothly based on a speed parameter. Which approach correctly achieves this?
Think about Unity's recommended way to blend animations based on parameters.
Using an Animator Controller with a Blend Tree allows smooth blending between clips based on parameters like speed. CrossFade on Animation component is less flexible and manual interpolation is complex and inefficient.