Last
week I was complaining about Get Component calls and how confused I was about
them. The next day I had another light bulb breaking moment where I watched a
video on Unity by Unity on Get Component and I finally saw it. I saw what I was
doing wrong. Then everything made sense. Part of my problem was I was not
thinking about a Get Component as a variable.
If(!Blah){
Int aNumber
= 7;
}
While(Blah){
aNumber
= 10;
}
I knew
you couldn’t do the above. Basically the variable aNumber only exists in the
above if statement. When the compiler leaves that statement that variable dies.
So last week when I was asking why doesn’t Update know about the Get Component
call from the Start function it was because I was doing the above. Trying to
set the value of aNumber in a function where that variable had ceased to exist.
But
when I figured out where I was going wrong worlds kind of opened up. I went
back through a fair amount of my code and corrected my wrongness. Nothing really
changed about the game after this fix. The frame rate didn’t change but the
code is more optimized right now. Also knowing how to set it up right means
that I will set it up correctly going forward and that is a good thing.
Also in my quest to do things that show no ‘real’
progress I put in all of the code for input from a game controller. Right now
my game can be played with a 360 controller. Before this it was all off of
keyboard inputs. Again nothing has really changed but I find this to be super
cool.
Anyway
I have been meaning to post a video of what I actually have going on right now.
So enough talk, watch this video of me playing my game.
Niiiiiice!
ReplyDelete