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"

This topic contains 5 replies, has 2 voices, and was last updated by  Simon (darkside) Jackson 3 years, 8 months ago.

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

    Wilber

    Hi,

     

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

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

    #5614

    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
    @SimonDarksideJ

    #5619

    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
    @SimonDarksideJ

    #5621

    Wilber

    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.

    #5647

    JoelR

    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

    #5649

    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
    @SimonDarksideJ

Viewing 6 posts - 1 through 6 (of 6 total)

The forum ‘Mastering Unity 2D Game Development’ is closed to new topics and replies.