Search Unity

Drawing a model on GUI

Discussion in 'Scripting' started by Morseton, Feb 12, 2016.

  1. Morseton

    Morseton

    Joined:
    Jan 15, 2016
    Posts:
    90
    I'm trying to draw a rotating model on the GUI, so I set a new camera with orthographic view and scaled it to have the same size as the canvas, but I'm having a problem.

    There is a controller object drawing stuff on the OnGUI event, and this is overlapping the model on the new camera, how can I make the OnGUI stuff from the controller draw stuff behind the model on the new camera?
     
  2. Teravisor

    Teravisor

    Joined:
    Dec 29, 2014
    Posts:
    654
    Maybe create canvas that's not in overlay mode(world space maybe?) and position it accordingly?
     
  3. CGPepper

    CGPepper

    Joined:
    Jan 28, 2013
    Posts:
    152
    Tested a scene where i have my Canvas set to screenspace - Camera. You can position objects between the camera and the ui, but strangely enough, 3d objects don't follow their parent inside the canvas hierarchy
     
  4. Teravisor

    Teravisor

    Joined:
    Dec 29, 2014
    Posts:
    654
    RectTransform's internal way of handling things is quite counterintuitive, I agree on that. Hovewer, I just added canvas in Screen Space - Camera, added text component to it and a cube to text component and cube moves when I move text just fine for me.
     
  5. Morseton

    Morseton

    Joined:
    Jan 15, 2016
    Posts:
    90
    I have this hierarchy:
    -Canvas
    ->GUI Cam
    -->Model here

    the model follows the camera like it should, like if it's really in the UI, but the stuff that is drawn using OnGUI event is drawing above the model, and I don't want it to be drawn above, i want it behind the model so the model shows in first plane, but it's not working =\
     
  6. Teravisor

    Teravisor

    Joined:
    Dec 29, 2014
    Posts:
    654
    Oh wait. I didn't notice. OnGUI is an old GUI, not Unity UI which uses Canvas and such. It doesn't really have a way of rendering anywhere except for overlay. If you're insisting on using it, only way I know is render GUI into rendertexture and then draw that rendertexture behind models that need to be in front.

    But then... Why not use Unity UI instead?
     
  7. Morseton

    Morseton

    Joined:
    Jan 15, 2016
    Posts:
    90
    Unity UI is when you put stuff on the scene inside the canvas? I don't know what Unity UI is, I just started using Unity :s

    Is OnGUI bad?
     
  8. Teravisor

    Teravisor

    Joined:
    Dec 29, 2014
    Posts:
    654
    Yes. In code to access it you need to have
    Code (CSharp):
    1. using UnityEngine.UI;
    - that namespace has all of its classes, components, etc.

    It's not bad, but it's old version of UI and has much less functionality. Not to mention it's harder to place in editor. Sometime in future it might become deprecated.

    The main point is, what you're struggling to do with OnGUI is easy with Unity UI.