Search Unity

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

Size of string in pixel

Discussion in 'Immediate Mode GUI (IMGUI)' started by Ryuuguu, Mar 17, 2008.

  1. Ryuuguu

    Ryuuguu

    Joined:
    Apr 14, 2007
    Posts:
    391
    If I am doing something like
    Code (csharp):
    1.  
    2. GUI.Label(Rect(50,50,50,50),"MyString")
    3.  
    Is there anyway to find out the size "MyString" will be on the screen?

    Cheers,
    Grant
     
  2. Dafu

    Dafu

    Joined:
    Aug 22, 2006
    Posts:
    124
    Yup,
    Try this:
    Code (csharp):
    1. stringSize = MyStyle.CalcSize( new GUIContent(MyString) );
    2. Debug.Log( "width: " + stringSize.x + " height: " + stringSize.y );
    3.  
    Where MyStyle is your current GUIStyle.
     
  3. Ryuuguu

    Ryuuguu

    Joined:
    Apr 14, 2007
    Posts:
    391
    Thanks

    Now off to read GUIStyle refernces pages.