Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GUISkin unable to find Style

Discussion in 'Scripting' started by kodagames, Dec 4, 2010.

  1. kodagames

    kodagames

    Joined:
    Jul 8, 2009
    Posts:
    548
    Hello All,

    I have a GUI Skin and in there I have 2 buttons setup in the Custom Styles Called "Ok" and called "Resume".

    My Button code is simple but for some reason Unity is not finding them:
    Code (csharp):
    1.  
    2. if (GUI.Button (Rect (65, 172, 229,75), "","Ok"))
    3.      {
    4.         //achievement! 
    5.      } 
    6.  
    Strange because it always worked before, Unless I've Always been calling it wrong?

    Attached is an image of my GUISkin and the error and here is all of my code:

    Code (csharp):
    1.  
    2. var DisplayLevelUp02 = false;
    3.  
    4. var PopupSkin : GUISkin;
    5. var LevelUp02 : Texture2D;
    6.  
    7. function OnControllerColliderHit (hit : ControllerColliderHit)
    8. {
    9.     //GreenBox
    10.     if(hit.gameObject.tag == "KeyFound")
    11.     {
    12.         Destroy(hit.gameObject);       
    13.         DisplayLevelUp02 = true;
    14.     }
    15. }
    16.  
    17. function OnGUI()
    18. {
    19.     GUI.skin = PopupSkin;
    20.    
    21.     if( DisplayLevelUp02 )
    22.     {
    23.        
    24.        //GUI Background Image KeyFound
    25.     GUI.Label (Rect (0,0, 600,450), LevelUp02, GUIStyle.none);      
    26.        
    27.        //Unlock open door
    28.        //pause game
    29.                      
    30.      //Ok Button Change the size 229 x 75  
    31.      if (GUI.Button (Rect (65, 172, 229,75), "","Ok"))
    32.      {
    33.         // achievement!
    34.      } 
    35.      
    36.      if (GUI.Button (Rect (400, 400, 95,38), "", "Resume"))
    37.      {
    38.         //resume Game
    39.         //un pause
    40.         //shouldDisplay = false;
    41.            
    42.      } 
    43.    
    44.    
    45.     }
    46. }
    47.  
    Can anyone see anything wrong Should I be calling the "Ok" and "Resume" buttons differently?
     

    Attached Files:

  2. StephenL

    StephenL

    Joined:
    Oct 18, 2010
    Posts:
    218
    Code (csharp):
    1. var DisplayLevelUp02 = false;
    2.  
    3. var PopupSkin : GUISkin;
    4. var LevelUp02 : Texture2D;
    5.  
    6. function OnControllerColliderHit (hit : ControllerColliderHit)
    7. {
    8.     //GreenBox
    9.     if(hit.gameObject.tag == "KeyFound")
    10.     {
    11.         Destroy(hit.gameObject);       
    12.         DisplayLevelUp02 = true;
    13.     }
    14. }
    15.  
    16. function OnGUI()
    17. {
    18.     GUI.skin = PopupSkin;
    19.    
    20.     if( DisplayLevelUp02 )
    21.     {
    22.        
    23.        //GUI Background Image KeyFound
    24.     GUI.Label (Rect (0,0, 600,450), LevelUp02, GUIStyle.none);      
    25.        
    26.        //Unlock open door
    27.        //pause game
    28.                      
    29.      //Ok Button Change the size 229 x 75  
    30.      if (GUI.Button (Rect (65, 172, 229,75), "Ok"))
    31.      {
    32.         // achievement!
    33.      } 
    34.      
    35.      if (GUI.Button (Rect (400, 400, 95,38), "Resume"))
    36.      {
    37.         //resume Game
    38.         //un pause
    39.         //shouldDisplay = false;
    40.            
    41.      } 
    42.    
    43.    
    44.     }
    45. }
     
  3. mightymao

    mightymao

    Joined:
    Oct 21, 2009
    Posts:
    108
    Zeek, you have to assign a GUI Skin (The one where you created the custom styles Ok, and Resume) to the PopupSkin in the Inspector.
     
  4. kodagames

    kodagames

    Joined:
    Jul 8, 2009
    Posts:
    548
    @StephenL
    Taking out the first set of parentheses ("") in front of "Ok" and "Resume" uses Unity's default Button style adding them in uses your own custom images, hint ;)

    @MightyMao
    I had assigned the PopupSkin in the Inspector already, but I did rename the skin as well before all of this trouble started and it seems like Unity may have gotten stuck? So I renamed it again then reassigned it and presto :D

    I seriously appreciate the help from both of you guys, 2 thumbs up!
    Im not really that experienced yet so I was just hoping I wasn't doing something wrong with the code lol Im learning so much from everyone here scripting is not that easy :D and I thank you all!
     
  5. StephenL

    StephenL

    Joined:
    Oct 18, 2010
    Posts:
    218
    Sorry, I misunderstood what you wanted. That's what I get for skimming posts. :p