- Home /
Why the gui texture is not in the middle of the screen and how can i change the texture size ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CrossHair : MonoBehaviour
{
public Texture2D crosshairTexture;
public Rect position;
public bool originalOn = false;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
position = new Rect((Screen.width - crosshairTexture.width) / 2, (Screen.height -
crosshairTexture.height) / 2, crosshairTexture.width, crosshairTexture.height);
}
private void OnGUI()
{
if (originalOn == true)
{
GUI.DrawTexture(position, crosshairTexture);
}
}
}
The texture is too much to the left side not in the middle. And it's very big i want it to be very small almost like a dot(cross hair).
Answer by Bunny83 · Nov 10, 2017 at 11:08 PM
Try moving the position line into your OnGUI method. The screen width / height may not return the correct values in the first frame. Do you use maximize on play? Try undocking the gameview and just resize the floating window to the desired size.
Your answer
Follow this Question
Related Questions
Why i'm getting UnassignedReferenceException when running the game ? 1 Answer
Help with deselection please 1 Answer
How can i keep the transform height while it's moving ? 1 Answer
How can i avoid mouse double click on second time to make my player idle ? 1 Answer
Resources.Load() don't loads texture in standalone build, when in unityeditor it does 1 Answer