Search Unity

2D texture on z axis

Discussion in 'Immediate Mode GUI (IMGUI)' started by Codingsoldier, Jul 16, 2010.

  1. Codingsoldier

    Codingsoldier

    Joined:
    Jul 16, 2010
    Posts:
    4
    Hi All

    So this may be a VERY noobish question but that would make sence since I am a noob at Unity so please bare with me and sorry if this questions been posted before, i couldent find an answer to it but anyway my problem is I'm trying to make a HUD in my game which is made up of two overlaping 2D images the code is set up like this for the HUD(which has to be infront):

    function OnGUI()
    {
    GUI.DrawTexture(Rect((Screen.width / 2 - 280), 0.0, 560.0, 291.0),
    HUDTexture,ScaleMode.StretchToFill, true, 0);
    }
    and the picture which has to be behind the HUD is set up the exact same just instead of "HUDTexture" it has its own name. I have tried changeing the z axis in the transform panel but it seems with the code set up that panel doesent change anything so is there anyway for me to put the image behind the HUD on a z axis with a 2D image within the code?

    thanks for the help in advanced
     
  2. AkilaeTribe

    AkilaeTribe

    Joined:
    Jul 4, 2010
    Posts:
    1,149
    What's the problem actually ? The underground picture do not appear ? Is it masked by the foreground picture (shown with the code) ? Is your foreground image transparent ?
     
  3. Codingsoldier

    Codingsoldier

    Joined:
    Jul 16, 2010
    Posts:
    4
    oh sorry I should have been more clear, because their both set up in the same location but not on a z axis the back image tends to sometimes appear on top of the HUD image instead of behind it. The HUD is a jail cell, and the background image is a prisoner my problem is the prisoner image is suppose to be behind the bars to show hes in the cell but because of the z axis problem he appers on top of the bars instead.So what im going for is I want the prisoner to stay behind bars. Is there anyway to set this up in the code to keep him behind bars? I hope this clears things up some.
    thanks
     
  4. AkilaeTribe

    AkilaeTribe

    Joined:
    Jul 4, 2010
    Posts:
    1,149
    You say the prisoner picture sometimes appears over the jail cell, what is the frequency rate ?

    And does the prisoner appears over the jail cell ? Or do they seem "mixed" (some part of the prisoner are in foreground AND some parts of the cell are in foreground), or is the jail cell not rendered for a few frames ?
     
  5. Codingsoldier

    Codingsoldier

    Joined:
    Jul 16, 2010
    Posts:
    4
    This happens about 50% of the time, I'll open Unity and everythings fine, the prisoner is behind bars, then close unity re-open and now hes on top of the bars and it goes on like this each time unity's open theres a 50/50 chance that he's either behind the bars or on top of them.

    No they dont merge or parts of the bars are mixed in with the picture and everything is still getting rendered normally. The prisoner appears on top of the bars because the prisoner is a bit smaller then the bars so you can still see the bars behind the prisoner image. Hope this helps, thanks
     
  6. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    The best way to get one GUI element overlaying another is to draw them in separate scripts (they can both be attached to the same object if that is convenient). Set the GUI.depth property to a different value for each script - the one with the lower depth value will be drawn over the other.
     
  7. Codingsoldier

    Codingsoldier

    Joined:
    Jul 16, 2010
    Posts:
    4
    thanx a million just added it in and closed unity re-opened and it still worked, done this about 15 times more and no problems that seems to have fixed it thanx again