Chpt 2 – when I run the Hero doesn\\\'t move/turn

Home Forums Books Mastering Unity 2D Game Development Chpt 2 – when I run the Hero doesn\\\'t move/turn

This topic contains 6 replies, has 2 voices, and was last updated by  Simon (darkside) Jackson 2 years, 1 month ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #9255

    progrmr

    Experienced .NET guy here (15 years, but business not game programming). Using Unity 5.3.2f1 Personal.

    I’ve gotten to the end of Chapter 2 and I think I’ve got everything hooked up right but there’s no change in the Hero’s direction based on my keyboard input

    Here’s a screenshot of Unity before I try to run, and another for while in Game mode, and the code from the Movement script – any idea what I may be doing wrong?

    #9256

    progrmr

    haha, I just saw the error at the bottom of the screenshot with the game running saying “Input Axis Horizontal is not Setup”…I guess I need to look into that.

    Did I miss something in the text?

    #9257

    progrmr

    Of course, now that I posted everything I figured it out…had a space in my controller script…1 character…make ya or break ya 🙂

     

    #9261

    Lol, glad you got it sorted.

    Yeah, even Unity is case and space sensitive in code 😀

    If you hit anything else be sure to let me know.  ALso don’t forget to grab the code files from the packt site for reference.

    Simon (Darkside) Jackson
    @SimonDarksideJ

    #10015

    Jason

    Regarding Ch 2 “Accessing Controllers from a Script”

    You state in the book to use “private Animator anim;” When I use this, I get a Null Exception at the line of code “anim.SetFloat(“speed”, Mathf.Abs(movePlayerVector));”. I realized that anim is never assigned. So I made it public so that I could drag the gameObject containing the animation into the anim variable space in the Inspector window. That allows it to work, and I can move the character and see the animation.

    So my question is; is there a line of code missing in the book to initialize anim in the script (as a private variable) rather than via drag and drop in the Inspector window (as a public variable)?

    It seems that the second bullet item in this section is missing the new code needed for this, as the only code shown is code that was already put into place earlier in the chapter.

     

    #10017

    Jason

    Sorry. This should be referrencing Ch 3

    #10043

    lol, you found one of my last remaining errata in the book which the proofreaders messed up on me and I missed it.

    Basically the problem is in the Awake function, which the text tells you to discover the animator from the scene, however the line is missing :S.

    However if you read further down in the “Extra Credit” section, the awake function is detailed in full. (basically they took the wrong line out of the previous example)

    The full Awake function should look as follows:

     

    Hope this helps.

    Simon (Darkside) Jackson
    @SimonDarksideJ

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

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