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 trialPauliina K
1,973 PointsWhat does this code mean?
I understand everything else in the code, but I'm just wondering if someone could explain this part of the code bit by bit? How can this line make the frog move when pressing a button? I get that everything else plays a role, obviously, but the code doesn't work without this line, so what exactly is it that this code does? (I understand the if-statement itself, but I just don't understand what the code that gets executed when it's true means) And how can the same code, but with 0f, make the animation stop?
playerAnimater.SetFloat ("Speed", 3f);
1 Answer
Becky Steele
16,229 PointsHi Pauliina!
This line of code "grabs" the playerAnimater object's "Speed" parameter and performs a setter method on it, called .SetFloat().
The arguments that the .SetFloat() method receives can vary (see here), but in this case, it's assigning ("setting") the playerAnimater's "Speed" parameter (variable) to "3f", and 3f is three of Unity's default units.
I'm not entirely certain, but it stands to reason that your playerAnimater would move without knowing the correct speed, therefore why this setter method is vital to the script.
Here's a great guide to default and assigning new parameters to Animator objects.
Matthias J.
20,355 PointsMatthias J.
20,355 Pointswith that line you say how fast the playback speed of the animation shall be.
so when you press the key you set the animation speed to 3f and when you release it you set it to 0f. (a car which is standing still also "drives" with 0mp/h (km/h)) :)
i hope i dont tell nonsense but this is as far as i remember and what i found in the unity docs :)