- Home /
Question is off-topic or not relevant
Understanding UI Logic
So, a simple question, with, probably, a not so simple answer. I am really having a hard time wrapping my head around UI logic and how to approach it programmatically.
Don't get me wrong, I can create buttons, text, sliders, windows, what have you. But I am really struggling with the logic behind it all, how one flows into the next without the need for reproducing similar assets (IE score text, or buttons).
I feel like the understanding is within arms reach, but I feel so blind right now by my own ignorance. And part of that is not even knowing where to begin to search for answers (apart from simply asking here, as I am doing). I am not sure that I even know what I am asking. I have an issue, but I am not quite certain what the question actually is.
Hopefully someone can point me in the right direction.
As an aside, I have already approached my UI design from a few different angles. At first I was basing everything on button presses. Example: PlayButton does X things. Then I tried creating things functionally. Exmaple: ShowMenuScreen(); ShowHighScoreScreen(); etc. But that seemed like I would be rewriting alot of the same code for minimal change. So then I thought, alright, why not make a UI based on 2D planes. when I need a certain "screen" just instance the plane; but again I thought that would lead to alot of repetition in creation, what if I needed a certain button in multiple places?
Obviously this shows a huge lack of understanding regarding programming in general, which I don't deny, but this aspect of game creation is really eluding me right now.
So, thank you to anyone that can shed a little bit of light on the subject.
Cheers!
I guess I should mention that I had not approached UI via scenes, simply because I had hoped to keep everything in one scene -- the game is very small (just a test thing).
Also, this may sound silly, I had an animated background and didn't want it to change from scene to scene.
So I'm not sure what you're asking. Perhaps you can post some code that you feel is being reproduced unnecessarily?
That's the thing, code-wise I am not quite sure where to even start.
For instance, my current iteration of my game is one scene, with all my UI elements as GUIText elements and GameObjects (used with the text as buttons / colliders).
Right now to go from the Start Screen to the Play Screen, all I am doing is setting the alpha on the objects I don't / do want to see. I$$anonymous$$ hide play button, show score text.
This however I felt was a really bad way to go about UI design, since all the code for switching "scenes" is within each button, and if I had a pause, play, restart, etc buttons, that is alot of code spread out over alot of elements.
So then I had thought about having some kind of "ScreenHandler" object where I would make a function for each screen in an ON phase and an OFF phase. I$$anonymous$$ $$anonymous$$ain$$anonymous$$enuScreenON(); and $$anonymous$$ain$$anonymous$$enuScreenOFF(); The idea was that I could call each function as needed from anywhere else within my game.
However, even this seemed needlessly complicated, since I had to then reference the ScreenHandler object from alot of different places.
So, now I have stepped back and tried to re-evaluate my logic, and found that I am actually having a hard time understanding how I should approach the issue.
...
Hopefully that helps a bit with my $$anonymous$$dset, and my issue? :p Sorry!
You should post this on the forums; UnityAnswers is for specific questions that have an objective answer, and this is a discussion/debate question, which this site software can't really handle.