Ok, so this is very weird and I feel like I’m imagining it. But, it’s happening, and I’d like to try and understand why so hoping someone could help me.
I was following along with Rick, but when I pressed play and tried the game, I was getting no value detected from the Input.GetAxis, it was just printing out zeroes:
Also the console log wouldn’t scroll, I had to keep putting it down to the bottom. (I guess Unity is thinking it’s just the same messages so not bothering to scroll?)
I fiddled around for a while but couldn’t see anything I’d done wrong. In the end, I went to Github and found Rick’s code for the lesson. This had Horizontal and Vertical, which I hadn’t got to, but anyway I pasted it into my Update function:
And voila, this worked:
Input values displayed. They end up showing either 1 or -1 depending on which direction I hold, and they stay there. The log also scrolls.
So great, working. But I want to know what I did wrong, because Rick’s not always going to be there with code for me to copy! I’ve gone through my commented lines character by character and they are identical with what I copied from Rick. So, I started doing some testing. I thought maybe there was something in my Unity setup that meant it wouldn’t work without both axes. So I commented out Rick’s Vertical lines and tried. Aha! It stopped working. I put them back. Uh-oh. Still not working. I put mine in. Still not working. I’ve re-ordered, added arbitrary extra Debug statements - nothing again.
So I deleted the contents of the Update function except my commented original lines, and pasted back in from Rick’s code on Github. Pressed play. Working!! Stopped it, pressed play again, still working. Added in an extra Debug.log just with random text: input no longer read.
This is very odd, but basically the behaviour I’m seeing is: when I write exactly the same characters as Rick myself, it never works - input is always read as 0. When I paste in Rick’s code, it works. Until I make any other change to the code, at which point it stops working.
I am totally at a loss, but I can reproduce this every time. Currently I can only put this down to maybe there’s a weird Unity bug where it’s not correctly compiling the file unless … I don’t know? A special character exists that’s being pasted in from Rick’s code? There’s nothing visible. I noticed in the video that Rick’s VS Code shows character encoding “UTF-8 with BOM” while mine was just “UTF-8”. I changed that to match his but it doesn’t seem to have helped. I’m currently using Unity Editor v2021.2.7f1, so a little older. I’m going to try and instal a new version and see if that helps. But I wanted to post if only because it’s getting late and I’m tired and tomorrow I might actually think this was a dream.