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 has 6 replies, 2 voices, and was last updated 4 years, 7 months ago by
Simon (darkside) Jackson.
-
AuthorPosts
-
February 5, 2016 at 6:30 pm #9255
progrmr
GuestExperienced .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?
February 5, 2016 at 6:33 pm #9256progrmr
Guesthaha, 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?
February 5, 2016 at 6:43 pm #9257progrmr
GuestOf course, now that I posted everything I figured it out…had a space in my controller script…1 character…make ya or break ya 🙂
February 6, 2016 at 8:22 pm #9261Simon (darkside) Jackson
KeymasterLol, 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
@SimonDarksideJJuly 7, 2016 at 3:58 am #10015Jason
GuestRegarding 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.
July 7, 2016 at 4:47 am #10017Jason
GuestSorry. This should be referrencing Ch 3
July 9, 2016 at 9:37 am #10043Simon (darkside) Jackson
Keymasterlol, 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:
1234567void Awake(){// Setting up references.playerRigidBody2D = (Rigidbody2D)GetComponent(typeof(Rigidbody2D));playerSprite = transform.Find("PlayerSprite").gameObject;anim = (Animator)playerSprite.GetComponent(typeof(Animator));}Hope this helps.
-
This reply was modified 4 years, 7 months ago by
Simon (darkside) Jackson.
-
This reply was modified 4 years, 7 months ago by
Simon (darkside) Jackson.
-
This reply was modified 4 years, 7 months ago by
Simon (darkside) Jackson.
Simon (Darkside) Jackson
@SimonDarksideJ -
This reply was modified 4 years, 7 months ago by
-
AuthorPosts
- The forum ‘Mastering Unity 2D Game Development’ is closed to new topics and replies.