Saturday, November 11, 2017

Today's Unity Lessons Learned - Canvas Pop-ups and OnGUI() for Input

As you might already know, I'm working my own indie game, EvoWars.

It's a work in progress and, as of now, I've released my v0.1 Alpha.

Today, I've been working on implementing a couple of new features per suggestion from folks on Kongregate.


So, that's what I worked on today.  And I came up with a nifty trick (maybe others have already discovered it).  If I want to create a new pop-up menu or options screen, I create a new canvas GUI object and build the entire screen as I want it.

Then using the 'enabled' bool variable on the canvas script component of the canvas gameobject, I can turn on and off the canvas.  This allows me to create the menu as part of the scene, rather than building a scene for some options settings.

Again, I'm sure this isn't anything new, but it was a new idea for me.  I've since used it in conjunction with buttons.  The script on the button is set to the canvas game object's canvas component and then I simple check or uncheck the box depending on what I want the button to do.

It was that simple.

OK.  Back to the questions that Pessimissed asked above.  The 'quit' button was an artifact of releasing an .exe version early on.  I just removed it today.

And now I've added an options button that allows you to turn on and off the music or sound.  Music is the background music attached to the sound manager class and sound is the sound effects in game.

The sound effects are a little bit harder to manage because I create a sound source for every unit spawned... that way you could have multiple attack sounds going at once.  To handle this, I'm creating a new global bool variable for sound effects.  And the sounds effects have to pass a logic criteria before being played.

This isn't the most efficient way to do this, but it works.

And when you're an indie game developer, sometimes you just do what works.  I will have releases in the future where I refactor my code and maybe find a better way to handle this type of condition.

But for now, it gets the job done and don't fix what ain't broke.

--
The other idea I had after implementing this little pop-up menu with options is to create a pause menu in game.  I wasn't sure how to handle frame rate independent inputs, so I researched it.

I found an article by Sophie Houlden on handling Super-fast input in Unity and how she used the OnGUI() function to grab inputs.  It seems to make sense and combining that with Time.scale = 0 | 1 I can pause the game action on the scene.

I didn't have enough time this morning to get 'pause menu' built out, but it shouldn't take long in theory.  We'll see what the effort on that will be.

I'll be tackling some of the other comments and feedback I received on Kongregate in the future.  And if you have ideas and suggestion, please let me know.  I'll figure out how to work it into the game if I can and you'll be listed in the game credits as a tester!

Cheers!
Alex

No comments:

Post a Comment