Hello everyone. I want to make my game user-friendly, so I have a small question.
I have a couple of boolean variables, called isFreezed, isBoosted, isJumping etc. and I want to list only the TRUE ones in a panel.
The thing is that if I use the primitive method on putting text then replacing it, it goes wrong leaving some blank spaces because I can’t know which one is active and which one isn’t.
I am fairly new to Unity, been working for about almost 1 month, so please explain as for-newbies as you can. Thanks!
I think you use some code like this:
string AppendText(string sourceText, string addText, bool appendText)
{
if(!(appendText))
return sourceText;
return string.Format("{0} {1}", sourceText, addText);
}
// and somewhere in your code:
string myText = "";
myText = AppendText(myText, "isFreezed", isFreezed);
myText = AppendText(myText, "isBoosted", isBoosted);
// etc.
I don’t see where you would have additional spaces.
If you use a Vertical Alignment group, the ones whose GameObjects are inactive won’t take up space.
I will give these a try. Thanks guys!
Depending on what you’d like to achieve, you probably want a subset of Unity’s Auto Layout features, which include Vertical, Horizontal, and Grid layouts, as well as a neat Content Size Fitter which might also help for anything you’d like to display around the bools you mentioned.