- Home /
Drawing a targeting reticule
I want to draw a reticule to the centre of the screen. I'm using this code inside OnGUI():
GUI.DrawTexture(new Rect((Screen.height/2)-5, (Screen.width/2)-5, (Screen.height/2)+5, (Screen.width/2)+5), texReticule1, ScaleMode.ScaleToFit, true, 1.0F);
(The image is 10x10 pixels, and is supposed to stay that way on screen).
It's not drawing to the centre. Instead, I can only see it if the screen is not set to a widescreen mode. It appears half off the bottom of the screen, half on (in 4:3 ratio). It's so large that, if it was all on the screen, it would take up a full quarter of it.
Jesse is correct, you have your Screen .width and .height backwards, and you have it set as bounds. Try Rect(Screen.width/2-5, Screen.height/2-5,10,10)
Answer by Jesse Anders · Dec 14, 2010 at 10:53 AM
Not looking at the docs right now, but I think the arguments to the Rect constructor are x, y, width, and height, not the bounds of the rect.
Ah, thanks a lot. I guess I should have read that more carefully. Although, I'm especially embarrassed I got height and width the wrong way around. >_<