Navigate

Thursday, November 15, 2018

Brain*Mart: Instantiating UI and Berserking Zombies

So last time I discussed a few goals I would like to reach for the project:
1. Clean up the code.
2. Add some art.
3. Create a demo.
4. click-able (mouse) controls.
5. Audio.
6. Transition zombie thought clouds to the UI instead of game-space.

I was not insanely productive.

Possibly because I expected it to be the most challenging, I focused on number 6, Turn the world-space thought cloud UI into actual UI elements on Canvas. This would solve a few issues--such as the thought clouds rotating with the zombie as it changed directions, as well as, looking kind of odd floating feet above the rest of the world.

Before I get into the details of the latest updates, here's a quick video showing off a few of the accomplishments since the last update:



So I needed a UI element that translated world-space coordinates to 2D coordinates on the canvas. Within five minutes of searching, I found a great video on Youtube that showed a simple way to achieve this:

https://www.youtube.com/watch?v=0bvDmqqMXcA.

Following along, I was able to get a text object to follow the player, and later a zombie. I was super excited and imagined I had achieved an early success.

BUT, because my zombies are instantiated, that means I have to instantiate the UI elements too. Not only do they need to be instantiated, but I have to be able to turn them on and off, as well as adjust colors. And since they were on the UI canvas, and not children of the zombie--I had to find them, reference them, and get access to their scripts. Because I wasn't using childed objects, I had to rewrite almost every script to gain access to the UI elements in the canvas. I feel like my GetComponent references resemble that of an old telephone switchboard being operated by a chimpanzee.

It took me the whole week of working a few hours a night. And it had the wonderful result of setting me back on my first objective (cleaning up the code). It's been a real joy figuring this all out.

Once I succeeded, it was a wonderful feeling. Though I did create some annoying bugs in several other scripts.

But the more exciting news for me was figuring out the Berserk UI feature. This has been my largest worry. I knew since I originally conceived this idea, years ago, I wanted zombies to get so hungry that they went Berserk and tried to eat the people in the store. And I knew I wanted to illustrate that timer with a thought cloud that slowly filled up with a color (red in my case). But I didn't have a clue how to incorporate it. Luckily, I found another helpful video:

https://www.youtube.com/watch?v=4fYd6-RFp_M.

The script looked really simple, so I skipped to copying and trying to make it work myself. FAIL. Only by watching the video did I realize that Unity had handy sprite fill options in the image component. It's almost too easy to use, but I quickly got my Berserk Visual Timer up and running, making the project feel like it's really coming along.

After that, I needed a break--finally beating Halo 3 and getting pretty far into Fable. Xbox Game Pass is a very dangerous distractor--but playing great games is also really inspiring.

I've since created a functioning Berserk Mode that causes the zombie to flash red and chase the player at an increased speed. If the player doesn't feed the zombie before the berserk mode is over, the zombie simply leaves.