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 trial

Game Development How to Make a Video Game Player Input and Cameras Move the Player with Animation

Angus Eliott
Angus Eliott
3,793 Points

float: Get or Set?

I was told to type out the following code:

    void FixedUpdate() {
        if(movement != Vector3.zero) {
            playerAnimator.SetFloat("speed, 3f");
        }
        else {
            playerAnimator.SetFloat("speed, 0f");

        }

Microsoft Visual Studio said that playerAnimator.SetFloat did not exist. and when I rendered the game in Unity, it told me that it could not be rendered because of a scripting error. Microsoft Visual Studio suggested I use playerAnimator.GetFloat instead. but when I rendered it in Unity again, the frog just didn't move.

2 Answers

J.D. Sandifer
J.D. Sandifer
18,813 Points

Ted's on the right track here - there are a couple subtle errors. I believe you want those lines do read more like this:

playerAnimator.SetFloat("Speed", 3f);

Notice the capital 'S' in speed and the second quotation mark goes before the comma. You want two arguments - a String ("Speed") and a Float (3f) - not one String ("Speed, 3f").

Just make the same type of correction to both those lines and you should be good.

I'm not actually taking this course, but when I looked at the video the first argument in both SetFloat methods is "Speed" with a capital S, rather than the lower case s you have in your script. Perhaps that is causing the problem.