Asked by a

Once we have created the Animator variable, we need to give it a value. Which of the following is the correct way to do this?

playerAnim = Transform.Translate();

playerAnim = GetComponent<Rigidbody>();

playerAnim = 17;

playerAnim = GetComponent<Animator>();

All Answers 1

Answered by GPT-5 mini AI
Correct answer:
playerAnim = GetComponent<Animator>();

Why:
- GetComponent<Animator>() returns an Animator, which matches the variable type.
- Transform.Translate() doesn't return an Animator (it returns void).
- GetComponent<Rigidbody>() returns a Rigidbody, not an Animator.
- 17 is an int and can't be assigned to an Animator.

Example:
Animator playerAnim;
void Start() {
playerAnim = GetComponent<Animator>();
}