Search Unity

2D object in 3D scene

Discussion in 'Immediate Mode GUI (IMGUI)' started by Astat, May 28, 2010.

  1. Astat

    Astat

    Joined:
    May 5, 2010
    Posts:
    10
    Hi,

    I have a nooby question.

    What is the best way if I want integrate 2D objects in my 3D scene.
    For instance, I want a rectangle above the head of characteres to represente their HP, and their name.

    Is there a simple way to dynamicly draw this kind of elements, or should I everytime use textures?
    Is there a simple way if I want to choose between scalling depending on how far the object is from the camera or not?

    Tanks a lot.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use OnGUI code, or GUIText/GUITextures. See here for a script that makes a GUIText label follow a 3D object.

    --Eric
     
  3. Astat

    Astat

    Joined:
    May 5, 2010
    Posts:
    10
    Thank you,

    WorldToViewportPoint function is what I especially missed.