Search Unity

GUI legacy

Discussion in 'Editor & General Support' started by om3, Jan 9, 2015.

  1. om3

    om3

    Joined:
    Dec 11, 2014
    Posts:
    14
    Hi, I use unity 4.6 and not found any resources of the GUI legacy. It is deprecated?
    Should I continue using?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It depends on what you're talking about...OnGUI code isn't legacy and isn't deprecated, and won't go away any time soon if ever since the entire editor GUI is built on it. The old GUIText and GUITexture components still exist, and don't seem to be marked as deprecated, though there's no reason to use them at this point.

    --Eric
     
  3. om3

    om3

    Joined:
    Dec 11, 2014
    Posts:
    14
    Ok @Eric5h5, I'm trying to attach any text in a gameobject as an over label.

    Prefab code:

    Code (CSharp):
    1.     void OnGUI ()
    2.     {
    3.         GUI.contentColor = Color.black;
    4.         Rect label = new Rect ();
    5.         label.x = worldToRect (transform.position).x;
    6.         label.y = worldToRect (transform.position).y;
    7.         label.width = 100;
    8.         label.height = 100;
    9.         GUI.Label (label, "test");
    10.        
    11.     }
    12.     ///
    13.     Vector2 worldToRect (Vector3 WorldPosition)
    14.     {
    15.         Vector2 v = Camera.main.WorldToScreenPoint (WorldPosition);
    16.         return GUIUtility.ScreenToGUIPoint (v);
    17.     }
    18.     //
     
  4. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    If that works for you, keep using it.