Search Unity

Positioning GUI Texture

Discussion in 'Immediate Mode GUI (IMGUI)' started by ddulshan, Jan 20, 2015.

  1. ddulshan

    ddulshan

    Joined:
    Mar 16, 2014
    Posts:
    190
    I'm having problem resizing the Textures. And I need the textures to be in exact position no matter the Screen Aspect Ratio, Resolution. Here's a layout of what I need. How to do it through coding and I've attached my current code.



    Code :

    Code (CSharp):
    1. var playImage : Texture;
    2. var optionImage : Texture;
    3. var exitImage : Texture;
    4.  
    5. var myStyle : GUIStyle;
    6.  
    7. function OnGUI ()
    8. {
    9.     if(GUI.Button(Rect(Screen.width/2, Screen.height/2, 190, 40), playImage))
    10.     {
    11.         Debug.Log("works!");
    12.     }
    13.  
    14.     if(GUI.Button(Rect(Screen.width/2, Screen.height/2, 190, 40), optionImage))
    15.     {
    16.         Debug.Log("works!");
    17.     }
    18.  
    19.     if(GUI.Button(Rect(Screen.width/2, Screen.height/2, 190, 40), exitImage))
    20.     {
    21.         Debug.Log("works!");
    22.     }
    23. }
     
  2. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    Have you tried wrapping the Screen.width/2 in a mathf function to round it off to an integer?

    Mathf.Floor(Screen.width/2)
     
  3. ddulshan

    ddulshan

    Joined:
    Mar 16, 2014
    Posts:
    190
    @monark : Can you show me a sample code line?
     
  4. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    1. if(GUI.Button(Rect(Mathf.Floor(Screen.width/2), Mathf.Floor(Screen.height/2), 190, 40), playImage))
    2. {
    3. Debug.Log("works!");
    4. }
     
  5. ddulshan

    ddulshan

    Joined:
    Mar 16, 2014
    Posts:
    190
    Thanks. I'll try it let ya know.