Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialYousef Almutairi
271 Pointswhat is the reason of this code?
void Start() { playerAnimator = GetComponent<Animator> (); }
can someone help me to understand this code, please? :)
3 Answers
Stijn De Vrij
2,086 PointsThe component "animator" should be attached to the player object. You can do this by looking at the object's inspector and clicking Add Component > Miscellaneous > Animator.
And indeed, you can name the variable "playeranimator" anything you want!
craig ohanlon
2,694 PointsCreate a variable called "playerAnimator" and get the <animator> component from the player object and assign it to "playerAnimator"
Yousef Almutairi
271 PointsBig thanks to you for answering me, so that component "animator" exist in a folder in unity, right? And I can name the variable "playerAnimator" to any different term, right ?
Susanna Remec
12,316 PointsAt the start of the script you are creating a variable called playerAnimator and making it equal to the Animator component on your GameObject. This is how you can grab it and change it or access it in your code. Unity components are conveniently set up too be easy to find and change.
Yousef Almutairi
271 PointsYousef Almutairi
271 PointsNow all is clear, Thank You :)