Code error from "chapter 3" – section: "Accessing controllers from a script"

Home Forums Books Mastering Unity 2D Game Development Code error from "chapter 3" – section: "Accessing controllers from a script"

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #5613



    I’m getting an error from the line of code listed below.  Anyone ran into this?

    anim.SetFloat(“speed”, Mathf.Abs(movePlayerVector));


    My goodness that was an ordeal trying to access the forums from my mobile
    (and all my post disappeared)
    *never mind I’ll try again when I got home

    Simon (Darkside) Jackson


    Right, let’s see if this works! 😀

    Ok, need a bit more detail on the error you are seeing with the above line.

    Off the top of my head, here are the possible issues you could face with that line:

    – You haven’t declared the properties in that file (anim / movePlayerVector)
    – You haven’t initialised the anim property in the start method
    – you haven’t attached the Animator to the GameObject the script it is attached to
    – You haven’t added the “Speed” property to the animator controller

    Hope this helps

    Simon (Darkside) Jackson


    Sorry to hear that Simon.  I got it to work.  I noticed I had two scripts as components to the game object.  All good now.


    Yes, I believe the problem is pg. 79 at the very bottom is missing

    anim = (Animator)GetComponent(typeof(Animator));

    this resolves itself when the code is changed on pg 84


    You are right, looks like the new part of the script (shown in bold) got cut from page 79 and moved to page 84.

    Very odd, not sure what happened there.

    Good catch Joel.

    Simon (Darkside) Jackson

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Mastering Unity 2D Game Development’ is closed to new topics and replies.