I made a sight that when i activate it a crosshair appears, the question is when i check maximize on play its changes the position of the crosshair, so i want to know if ill change the screen resolution will the crosshair appear in somewhere else in the screen?
and i use a rect called pos to draw the crosshair, and then i draw it like this
pos.y = …;
pos.x = …;
Basically my question is how to draw a cross hair in a exact y and x position i choose and that position wont change if i will change the screen resolution.
When drawing it, declare its position as:
new Rect(Screen.width / 2 - crosshairwidth / 2, Screen.height / 2 - crosshairheight / 2, crosshairwidth, crosshairheight)
That will put it in the center of your screen no matter what the resolution is.
using UnityEngine; using System.Collections;
public class addingCrosshair : MonoBehaviour {
public Texture image;
void OnGUI() { GUI.DrawTexture(new Rect((Screen.width / 2 - image.width / 2), (Screen.height / 2 - image.height / 2), image.width, image.height), image);
just copy paste this and it will work perfectly.