Thursday, July 30, 2015

Dev Update #9 Productivity Game - Rogue-Like Prototyping

I did a tutorial for Unity for a 2d Roguelike
I decided to modify this Game so that every time you do a task, another tile/part of the level loads and then once all tiles/parts are loaded, you can play the level.

I've made some progress in this.

I used:

while (!clicked)
yield return new WaitForSeconds(0.01f);
clicked = false;

To make each piece of the level wait for a click until loading the next piece.

(I'm finding it difficult to properly format the code on blogger.)

Then I tried to make the Sound and Player Object wait to load until after the level was loaded, but I've had some difficulty.

First, I thought I would just turn them off in the inspector and then turn them on with a script.  It turns out, accessing a deactivated object is difficult in Unity, because most of the easy ways to access an object require the object to be active.

Second, I thought I would try to create a script that had a reference to the Object, and then I could access the reference from the script.  I spent a long time trying, but could never get it to work.  It might not be possible.

Then I decided to leave the Player Object active and simply toggle the Player Script and and Player SpriteRenderer.  This worked on the first level, but after the next level loaded, there was some code that was trying to use the Play Script, but couldn't because it was deactivated.

I'm not yet sure how I will solve this.

Dev Update #8 UnityUI Tests

I've been streaming some of my work on Unfortunately the stream is too low quality to see what's going on. Mostly it's me trying things and then them not working. I do make a little progress, though. Also I don't have a webcam or mic hooked up currently so my only means of communication is through wordpad.

 I made a simple mockup of the UI with a prefab of a toggle. I tried to dynamically instantiate a list of those prefabs but I had trouble making the new instantiated toggles children of the canvas. I found a video about it on and downloaded the video using firefox's video downloadhelper addon so I could control playback speed. I used the code that was linked to this video, with a slight modification to use SetParent instead of Parent, to display a list of toggles that are children of the canvas. They scroll correctly and everything. Now I just have to apply this to my own project and I should be able to create a mockup for the new UI. I'm still not entirely sure what everything in the code does, but I'll figure it out.

 Update: I made a draft of this post a while ago but never posted it. After this post, I created 4 separate lists of toggles and connected them to the same scrollbar. They don't scroll evenly. Each list is centered instead of starting at the top and the longer the list, the faster it scrolls, but I moved on to something else which I'll describe in my next post.  I also added rudimentary health/xp/mana bars.