Search Unity

Problem Windows events

Discussion in 'Scripting' started by Dm1try, Jul 25, 2011.

  1. Dm1try

    Dm1try

    Joined:
    Jul 25, 2011
    Posts:
    8
    if (GUI.Button(new Rect(10, 10, 50, 50), btnTexture))
    {
    Debug.Log("Clicked the button with an image");
    }
     
  2. zine92

    zine92

    Joined:
    Nov 13, 2010
    Posts:
    1,347
    Please read this b4 posting. :D http://forum.unity3d.com/threads/97...-in-the-scripting-section?p=638874#post638874

    Give more details on what you are trying to do. Post some screenshots and put your snippets in a code tag.

    And according to your codes, i don't see any problems.

    Perhaps try this.
    Code (csharp):
    1.  
    2. var btnTexture : Texture;
    3. function OnGUI()
    4. {
    5.     if (GUI.Button(new Rect(10, 10, 50, 50), btnTexture))
    6.     {
    7.         Debug.Log("Clicked the button with an image");
    8.     }                      
    9. }
    10.  
    Then in your inspector remember to assign btnTexture. :D
     
  3. bdev

    bdev

    Joined:
    Jan 4, 2011
    Posts:
    656
    To do this you'd need to use a GUIContent
    Code (csharp):
    1.  
    2.  
    3. GUIContent content = new GUIContent( btnTexture );
    4.  
    5. if (GUI.Button(new Rect(10, 10, 50, 50), content))
    6. {
    7.     Debug.Log("Clicked the button with an image");
    8. }
    9.  
    10.  
    This will put the texture specified as a icon ( depending on the "button" GUIStyle )

    Avoid creating a new GUIContent every call though and just change the type of btnTexture to GUIContent.

    If your wanting to instead replace the button image ( background/ border) you'll need to use GUIStyle insteadl of GUIContent ( change the type of btnTexture to GUIStyle and use like this
    Code (csharp):
    1.  GUI.Button(new Rect(10,10, 50, 50), GUIContent.none, btnTexture )