Search Unity

GUI.DrawTexture Positioning

Discussion in 'Immediate Mode GUI (IMGUI)' started by PirateMonkey, Jul 25, 2014.

  1. PirateMonkey

    PirateMonkey

    Joined:
    Jun 24, 2014
    Posts:
    28
    Hey,

    So this might be a stupid question but I am somewhat new to Unity and find this confusing. I am currently making a game that uses a health bar and speed boost bar. I have been drawing them as rectangles on the screen using GUI.DrawTexture(xPosition, yPosition, etc...)

    Where xPosition = Screen.width/2;

    I would therefore expect the rectangle to be located in the middle of the screen (or just off since it moves from the bottom left corner), but instead it pops up maybe 1/4 way from the left. Why is it doing this?

    I suspect it has something to do with screen space vs world space, but don't know enough about it. Any insight would be appreciated!
     
  2. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    You want to center the texture I'm assuming?

    You need to say:

    Float x = (screen.width - texture.width) /2 and that will have it center properly.
     
  3. PirateMonkey

    PirateMonkey

    Joined:
    Jun 24, 2014
    Posts:
    28
    The bar is already on the left side, so doing this would only move the bar further left. I think something else is going on