How would I grey out buttons on my level list and unlock them when the level before it is completed?
I am kinda stumped with this. I am using OnGUI for my buttons but just can’t get them to be “unlocked”. BTW, this is for an iPhone Game, if it matters.
For starters, you might want to reconsider your UI approach as UnityGUI isn’t really optimized well for iPhone content. You should look into GUIText and GUITextures instead, they require you to do more work for UI functionality implementation but in the end that will offer far less of a performance hit (via draw calls) than UnityGUI. And yes, we do plan on optimizing UnityGUI a lot more, but I’m sharing the reality as of today.
How do you grey out and disable buttons? Simply set GUI.enabled to false and anything else after that will be greyed out and disabled.
var LevelOneEnabled = true;
var LevelTwoEnabled = false;
function OnGUI () {
GUI.enabled = LevelOneEnabled;
GUI.Button(...); // draw your level 1 button
GUI.enabled = LevelTwoEnabled;
GUI.Button(...); // draw your level 2 button
GUI.enabled = true;
}
Then you just write some code routine that checks if a level is completed and sets the variables as necessary (LevelOneEnabled, LevelTwoEnabled, and so on).
Well, todays trend is showing all levels (to prevent frustration from endles playing) and just make buttons inactive / grey. Maybe that should be better example
But that is exactly what setting GUI.enabled does. The buttons will still be drawn but they will be slightly greyed out and they won’t respond to mouse events. Try it and you’ll see!
Eh, im sorry It looks to weird for me I assume that it draws all or nothing if GUI.enabled is true or false but i didnt saw any identifier like if button is enabled or disabled. That confused me little
Thanks againg for the help but I have another quick question if you don’t mind. You said using Textures and Text would be better that GUI but this it just for a menu with nothing else going on should I still switch? Also, how do you read a touch on a guiTexture?
It’s certainly not a problem to tack on follow-up questions like this as they pertain to the discussion nicely.
To be specific and clear, I said to use GUITextures and GUIText as those are specific items apart from “Textures” and “Text”. Here are some relevant documentation links in case you need them:
Maybe yes, maybe no. How’s that for a vague answer? The truth is that you may very well get away with using UnityGUI if you keep the usage of it light, but please keep in mind that as you optimize your content for better performance the number of draw calls made will be critical, and UnityGUI can rack 'em up quickly. So if you have performance issues and your game needs optimizing, then this will likely be one area to look at first.