Hi guys,
i try to create a game with a crosshair in the middle of the screen.
When i lock the cursor with
Screen.lockCursor = true;
My Cursor isn’t exactly in the middle.
On the screenshot you can see my crosshair:
crosshairRect = new Rect (Screen.width/2 -10, Screen.height/2 -10, 20, 20);
UnityEngine.GUI.Label (crosshairRect, crosshair);
and the End of the green line is where my cursor really is.
When i press ESC to see my cursor again i can also see the cursor is, where the green line ends.
I would be very thankfull if someone could help me with this.
The code is completly wtitten in C#.
Greetings Thilo
Use GUI.DrawTexture; Label has things like margins and so on.
–Eric
Thanks for the fast answer.
But i got still the same problem.
UnityEngine.GUI.DrawTexture(crosshairRect, crosshair);
i’ve seen in the built version i get just problems in the height, not in the width.
I have two screens on my pc, maybe this could be a problem?
Does noone have an other solution to fix it?
i have “fixed” it now by changing it from:
crosshairRect = new Rect (Screen.width/2 -10, Screen.height/2 -10, 20, 20);
to:
crosshairRect = new Rect (Screen.width/2 -10, Screen.height/2 -20, 20, 20);
but this doesnt make sense to me.
For anyone with the same Problem, this is how i handled it:
- Lock cursor in the midle of the Screen
Screen.LockCursor = true;
- Instead of putting the Texture in the middle put it on your locked cursor like this:
crosshairRect = new Rect (Input.mousePosition.x-10, (Screen.height - Input.mousePosition.y -10), 20, 20);