Skip to content

Instantly share code, notes, and snippets.

@RimuruDev
Created December 10, 2022 13:26
Show Gist options
  • Save RimuruDev/d99ce55b0c42d9c4f597df842b4f8273 to your computer and use it in GitHub Desktop.
Save RimuruDev/d99ce55b0c42d9c4f597df842b4f8273 to your computer and use it in GitHub Desktop.
Drow Cursor
using UnityEngine;
public sealed class CursorSettings : MonoBehaviour
{
[SerializeField] private Camera _camera;
[Space]
[SerializeField] private CursorLockMode cursorLockMode = CursorLockMode.Locked;
[SerializeField] private string cursorTexture = "*";
[SerializeField] private bool isCursorVisible = false;
private void Start()
{
if (_camera == null)
_camera = Camera.main;
Cursor.lockState = cursorLockMode;
Cursor.visible = isCursorVisible;
}
private void OnGUI() => SightForShooting();
private void SightForShooting()
{
int size = 12;
float posX = _camera.pixelWidth / 2 - size / 4;
float posY = _camera.pixelHeight / 2 - size / 2;
DrawCursor(ref posX, ref posY, ref size);
void DrawCursor(ref float posX, ref float posY, ref int size)
{
GUI.Label(new Rect(posX, posY, size, size), cursorTexture);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment