- Home /
GUI.Label appearing behind GUI.Button
Hi all,
Trying to display a cooldown timer over the top of a spell button. No matter what I try, I seem to be unable to get the GUI.label infront of the GUI.button. GUI.depth does not work, as it is all processed in the same GUI Script.
Any ideas, references or something I am missing would be a great help
Excerpt of code from ONGUI function
//Omitted Code
function OnGUI ()
{
for(var i : int = 0; i < spellIcon.Length; i++)
{
if (GUI.Button (new Rect(Screen.width/2-400,Screen.height-100,64,64),spellIcon[i]))
{
if (cooldownTimer[i] <= 0)
{
cameraAimingScriptGO.gameObject.GetComponent(AimingRay).CastSpell();
cooldownTimer[i] = cooldownSpellTime[i];
}
}
GUI.Label (new Rect(Screen.width/2-400+50,Screen.height-100+40,64,64),"1");
//Cooldown Component
if (cooldownTimer[i]>0)
{
GUI.Label (new Rect(Screen.width/2-400,Screen.height-100,64,64),cooldownCover);
GUI.skin = guiCountdown;
GUI.Label (new Rect(Screen.width/2-380,Screen.height-68,64,64),""+cooldownTimer[i]);
}
}
}
//Omitted Code
Answer by Grieve_physics · Jan 20, 2014 at 04:25 AM
Found the Answer.
The issue lied in the application of GUI.skin.
By not resetting the GUI.Skin to null whilst is was in the for loop it created the weird effect described above.
Solution: Make sure that GUI.skin is reset if experiencing a similar issue.
Your answer
Follow this Question
Related Questions
UI Button order 1 Answer
GUI.Label positioning for many device resolutions 1 Answer
GUI, making main page lead into an instructions page 2 Answers