Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Drawing objects on top of the GUI with an orthographic camera?

Discussion in 'General Discussion' started by Tomnnn, Dec 8, 2014.

  1. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    I tried following 2 different tutorials for doing this, but they are very old and I could not reproduce them. I've attached my 2 camera settings, what is seen in the play view and how the scene is setup. The screenshots are from a simple test where I am using perspective cameras, as I tend to try to get a tutorial working before adapting it to my needs.

    Just tried a 3rd tutorial, still can't figure this out:

    1. Add a new Layer tag "gui".
    2. gui elements: Set Layer of your gui-elements to "gui"
    3. (first)gui camera: set Culling Mask to "gui" only
    4. add second camera (object camera at the same position as the first camera)
    5. object camera: set Clear Flags to "Depth only".
    6. object camera: set Culling Mask to everything except "gui"
    7. object camera: set Depth to a higher value than gui camera (e.g. gui camera -1, object camera 0)
    8. object camera: uncheck GUILayer

    The only thing in the scene is a cube and the 2 cameras.
     

    Attached Files:

  2. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    I just realized all of the tutorials were talking about GUITextures, not Texture2D which I have been using. That's the legacy-legacy system. I guess what I'm trying to do is impossible?

    I have the current-legacy system (lol) drawing a background image and I'm using the new gui system to draw text in the world above little 2D monsters which are drawn by the current-legacy gui. The new gui uses 3D gameobjects, so anything drawn with the new gui system is hidden behind the background image drawn by the previous gui system.

    Is there a workaround besides picking one gui system or the other? I just wasted enough time trying to do this alone & with tutorials that now I think it's about time to ask for help :D

    Help, please.

    --edit

    This seems to work. Hopefully it isn't doing something terrible to performance that is beyond my knowledge.

    Code (CSharp):
    1. public Texture2D img;
    2.     public Camera otherCam;
    3.  
    4.     void OnGUI()
    5.     {
    6.         GUI.DrawTexture(new Rect(0,Screen.height*0.5f,Screen.width*0.1f,Screen.height*0.1f), img);
    7.         GUI.Button(new Rect(Screen.width*0.9f, Screen.height*0.5f, Screen.width*0.1f, Screen.height*0.1f), "Button");
    8.         otherCam.Render();
    9.     }
     
  3. Ostwind

    Ostwind

    Joined:
    Mar 22, 2011
    Posts:
    2,804
    I think you might have better success to get proper answer if you get a mod to move this thread to either one of the UI sections :)
     
  4. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Do people other than me like the previous system better? :eek: it seemed that everyone had jumped ship.

    I do, however, apologize for intentionally posting this in this thread in order to amass views & get more people to assist. I will now voluntarily ban myself for 24 hours.

    selfban.png
     
    Last edited: Dec 8, 2014