Search Unity

Custom style in GUISkin not working

Discussion in 'Immediate Mode GUI (IMGUI)' started by Bridgeman, Aug 8, 2014.

  1. Bridgeman

    Bridgeman

    Joined:
    Apr 13, 2014
    Posts:
    33
    So for my main menu, I've set up a GUISkin. But there are two different kinds of buttons in my Menu. So for the second type of button, I've created a Custom Style in my GUISkin, which I gave the name "backbutton". I then defined that GUIStyle in the back button in my main menu script.

    The problem is, no text appears on the back button, even though I gave the button proper text in the script. However, if I set a texture for the background of my backbutton style, it shows up.

    So here's my script, the relevant part (the back button) is at line 51.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class MainMenu : MonoBehaviour {
    5.  
    6.     public GUISkin MainMenuGUI;
    7.     private bool isMenuOpen = false;
    8.     private int menuPage = 0;
    9.     //private float menuOffset;
    10.  
    11.     void Update() {
    12.         if (Input.GetKeyDown(KeyCode.M)) {
    13.             isMenuOpen = !isMenuOpen;
    14.             //StartCoroutine(Slide());
    15.         }
    16.     }
    17.  
    18.     void OnGUI () {
    19.         if (isMenuOpen == true) {
    20.             Time.timeScale = 0;
    21.             GUI.skin = MainMenuGUI;
    22.            
    23.             GUI.BeginGroup (new Rect (Screen.width / 2 - 320, Screen.height / 2 - 280, 640, 560));
    24.            
    25.             GUI.Box (new Rect (0, 0, 640, 80), "Main Menu");
    26.             GUI.Box (new Rect(0, 80, 200, 480), "");
    27.  
    28.             if (menuPage == 0) {
    29.                 GUI.Box (new Rect (200, 80, 440, 480), "Menu content");
    30.                 if (GUI.Button (new Rect (3, 83, 194, 50), "Button 1")) {
    31.                     menuPage = 1;
    32.                 }
    33.                 if (GUI.Button (new Rect (3, 133, 194, 50), "Button 2")) {
    34.                     menuPage = 2;
    35.                 }
    36.                 if (GUI.Button (new Rect (3, 183, 194, 50), "Button 3")) {
    37.                     menuPage = 3;
    38.                 }
    39.             }
    40.             else if (menuPage == 1) {
    41.                 GUI.Box (new Rect (0, 80, 640, 480), "Button 1 content");
    42.             }
    43.             else if (menuPage == 2) {
    44.                 GUI.Box (new Rect (0, 80, 640, 480), "Button 2 content");
    45.             }
    46.             else if (menuPage == 3) {
    47.                 GUI.Box (new Rect (0, 80, 640, 480), "Button 3 content");
    48.             }
    49.  
    50.             if (menuPage > 0) {
    51.                 if (GUI.Button (new Rect (440, 510, 200, 50), "Back", "backbutton")) {
    52.                     menuPage = 0;
    53.                 }
    54.             }
    55.            
    56.             GUI.EndGroup ();
    57.         }  
    58.         else {
    59.             Time.timeScale = 1;
    60.         }
    61.     }
    62.  
    63.     /*IEnumerator Slide() {
    64.         for (int i = 0; i < 10; i++) {
    65.             menuOffset = -(10 * i);
    66.             yield return new WaitForSeconds(0.1f);
    67.         }
    68.         menuOffset = 0;
    69.     }*/
    70. }
    71.  
    Screenshot of my custom style within my GUISkin:



    Screenshot of how it looks in-game:

     
  2. Bridgeman

    Bridgeman

    Joined:
    Apr 13, 2014
    Posts:
    33
    Bump, really need this resolved
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Your text color is 100% transparent.

    --Eric
     
  4. Bridgeman

    Bridgeman

    Joined:
    Apr 13, 2014
    Posts:
    33
    How can you tell?
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    By looking at the color, and seeing that the transparency is at 0%.

    --Eric
     
  6. Bridgeman

    Bridgeman

    Joined:
    Apr 13, 2014
    Posts:
    33
    Oh cool now it works
     
  7. Dylfin

    Dylfin

    Joined:
    Mar 7, 2014
    Posts:
    2
    Thanks, Eric, I'm stuck on this too. You really should know where to look to find this :)