Well – I did it. After slogging through the bullshit from my last post, I got everything laid out well.
There is one issue that I was having on the start screen after revamping things with regards to how the buttons work. In Unity you can create a button and have a transition effect (tint, scale or image swap). I did an image swap to match the game layout. I was reminded of why I did what I did when setting up the levels.
When I started this project, my initial thought was that I would have buttons be the main UI, just lay them out with the transition effect- all the animation code would be taken care of. There is a default state, a hover state (mouseOver), a pressed/clicked state and a disabled state. You can set images for each of those states. In my case, the hover state is a lighter square color. Pressing makes the state revert to “default” image.
Something stupid happened along the way. If you press down on a button, then it shows the “pressed” state… Then, while still holding the mouse down, drag your mouse off the button, it reverts the state of the button to the “hover” state. Even though the mouse is no longer hovering over it. It should revert to the default state, not act as if my mouse is still on it). This indicates that the mouse state detection only updates when a player releases the mouse.
When the mouse has no buttons being pressed, the mouse location is wherever the mouse actuall is on screen, and Unity seems to be able to deal with it as such… But, when you press the button, it seems to retain the location of where the mouse clicked, not where it is now. So when I leave the mouse position, while still having the mouse clicked, even though the mouse is no longer hovering over a button, when I leave the square, it acts as though the mouse has been released, and my location is still where it was when I clicked the square/button. I’m not going to waste time making a video now of it, but it’s annoying and I think that’s why I ended up doing something much more complicated than just using buttons for the state of my squares on the grid.
I forgot that was the case, however, and when creating the loading screen, started from scratch with… BUTTONS! And so now I have that dumb as shit issue. Oh well. Not going to worry about it. Too much work to try to fit my workaround from the gameplay into the level select screen.
Anyways, so the next bit of progress was saving a completed level to the playerprefs file so when you load the game, the next available level and all previous levels are now highlighted as selectable, and the player can do so. I need to do a little error checking because right now if I don’t have a level actually built, but the levelselect menu shows it as available, it will, of course, generate an error when clicking.
In the video below I demo the glitchy transition states for the buttons (note how I move off “4” and it suddently lights up? You’ll see when I hover over numbers they light up and if I press down, they go dark. If I move off while still pressed, they light up again as if I’m hovering over them (and will go dark if I move back over it)… only when I release the mouse button will it do the right thing).Then you can see how the available levels are highlighted when I return to the menu after completing a level.