Search Unity

GUIText has a mind of its own???

Discussion in 'Immediate Mode GUI (IMGUI)' started by Nick_Koufou, May 12, 2008.

  1. Nick_Koufou

    Nick_Koufou

    Joined:
    Apr 26, 2008
    Posts:
    9
    Hi,

    I am having this really bizarre problem with GUIText. I create a new project and add a GUIText component to the Main Camera. This by default appears at the top left corner of the Game view. If I rotate/scale the camera the text will stay at the top left corner as expected. If on the other hand I translate the camera, the text shoots across the screen in the same direction. Any ideas what could be going wrong here?

    Thanks
    Nick
    (Unity Indie 2.0.2f2)
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You're moving the main camera, so naturally the GUIText component moves too. GUITexts can't rotate, so that's why rotating the camera does nothing; scale does nothing if you have the GUIText set to pixel correct, otherwise that also affects it. Attach the component to some object that doesn't move instead. (Also, the coordinates for GUIElements are normalized, so 0.0 is the left/bottom edge of the screen, and 1.0 is the right/top edge. Anything outside of that range will be off the screen.)

    --Eric
     
  3. Nick_Koufou

    Nick_Koufou

    Joined:
    Apr 26, 2008
    Posts:
    9
    Ahhh, now I get it, didn't realise 3d object transformations affected GUI elements. Adding a GUI text game object to root works fine. Thanks Eric
     
  4. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Note: Not all gui is affected. GUI drawn in OnGUI is completely unaffected.
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, that's normally how you position them. The Z coordinate obviously doesn't affect depth, but it does allow you to set the order in which they're drawn, so you can layer them as desired. If you want resolution-independent text, turn off "pixel correct" and adjust the scaling. Only rotation doesn't do anything. For fun stuff, add a rigidbody component. ;) (Like this silly little thing I did ages ago, updated a bit just now. Also here's a package for it if anyone cares. In the physics manager, you have to set gravity to (0,-1,0) and the bounce threshold to 0 for it to work right.)

    --Eric
     

    Attached Files:

  6. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Haha awesome Eric. One of the most funky webplayers I've seen in a long time :wink: