Have you ever made a UI before? Yeah me neither. I had made
a basic UI HUD that displayed all of my player meters with just text. It worked
but was not pretty.
I started work with the thing I thought would be the
easiest. I made the artwork for the can teleport. Then if the ‘can teleport’
flag was true an object appeared and when the flag was false this object disappeared.
The effect was basically a light turning on and off. Simple enough. For the
player Ammo Counter I just had to change the font for the amount of Ammo then
position it over the Ammo Counter. Also pretty simple. Then I had to set up the
Player’s life meter…
My life meter is basically the life meter from Zelda but one
heart is equal to one heart (in Zelda one equals four). I didn’t exactly know
where to start so I went to YouTube and found a tutorial from a guy that I had
seen some videos from before. I watched his video that was in Unity 4 and some
of the things he was doing have been deprecated in Unity 5. So I opened a
different tutorial and watched basically 80 percent of it and figured out that
the way he was doing it was basically crazy. Damn. Opened another tutorial from
a thirteen year old watched two minutes closed it and said ‘if you want
something done do it yourself!’
I learned some things for both of the first two tutorials. I
kept those things. I spent like all of Wednesday working on this Life Meter. It
now works but it is the most convoluted Life Meter in code by far. Here is how
it works.
Deleted all heart containers
Draw all heart containers
Deleted all hearts
Draw all hearts
You can’t see this happening because it happens at a speed
of one thirtieth of a second. I was super tired when I finished this on Wednesday
but I had one more thing to do for the UI. That was display the current
secondary weapon. I made four symbols to represent a secondary weapon and the
text system worked pretty well so I copied that object then edited the code.
(HUGE MISTAKE FOR MY SANITY, but too tired to realize that.)
I deleted all of the text objects because this thing didn’t
need them. Hooked up the images to display on a case system. If case 1 display this case 2 display this and
so on. Run it worked great YES UI done! Then looked at my console log. Null reference
line 29. What?
I looked at line 29. It was fine. The UI object was hooked
up in Unity. I comment out all of the code in the case 1. Run the game. Null reference
line 37. What the?!
Repeat this process
until all of the functionality of the code is gone and then the Null reference
is gone. What the hell?!
I uncommented all of my code I restarted Unity because I
thought it was a Unity bug. Nope still a Null reference. There is no Null reference!
NONE! This shouldn’t be happening!
I should go to bed I
thought. The game works you just have something stupid happening. I went to
bed. I couldn’t sleep. I just kept thinking about this stupid thing that should
work! I got out of bed. I turned my laptop back on and stared at it for about
five minutes and found the problem. The duplicate object, the original object
that just displayed the text it had four image references that were empty, as
in the opposite of full. These image references were supposed to be full!
Anyone care to explain?
Yeah I deleted that object as it was no longer needed
anyway. Problem solved. Then I could go to bed and sleep soundly.
No comments:
Post a Comment