I learned a couple of simple things about Unity while putting together the basic pre-game UI.
1. Unity is very easy to use
It's VERY easy to construct simple game elements in Unity. Adding the visual game elements, writing code behind those elements and wiring the two up is very straightforward. I had expected that prototyping the pre-game UI would take a whole week. That I was able to do it in less than two was quite a shock. I suppose it helped that I've already worked through two tutorials that both took something like a full day of work to get through. I should point out that I haven't actually written the code that sends requests to the API and handles the responses from it. I expect that will take quite a bit of time.
2. Panel UI elements are your friend
When you need to show or hide groups of UI elements the recommended (according to a forum post I agreed with) way to do that is by containing elements in panels and showing or hiding the panels. I'd already sort of started putting the UI together like that when I came across the guidance. Grouping elements by panels also makes it a lot easier to structure the layout and ensure that it generally continues to work if the user operates at a different resolution than you do.
3. Unity is magical. Use that magic.
I ran into some problems when I started to actually write the code that made specific elements show or hide (you're actually calling GameObject.IsActive(bool newState) method to do this). There are methods in Unity for finding the child objects of UI elements by name but I wasn't looking forward to writing a bunch of "traverse tree structure for child element with name" code. Luckily, I came across a related question in the forums that finally made an aspect of Unity click for me in a way that it hadn't before.
In Unity, you can write a class in C# and then add that class as a component to a game element in the UI. If you add public properties to that class in code, those properties magically appear in the game design UI as fields of the component. You can then drag other game elements of the UI to those fields. References to the corresponding game objects then become available to the C# code.
It's freaking magical.
As is Google searching.
No comments:
Post a Comment