45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
public class SimpleCrosshair : MonoBehaviour
|
|
{
|
|
[Header("Crosshair Settings")]
|
|
public Color crosshairColor = Color.white;
|
|
public float crosshairSize = 10f;
|
|
public float crosshairThickness = 2f;
|
|
|
|
void OnGUI()
|
|
{
|
|
// Calculate center of screen
|
|
float centerX = Screen.width / 2f;
|
|
float centerY = Screen.height / 2f;
|
|
|
|
// Set the crosshair color
|
|
GUI.color = crosshairColor;
|
|
|
|
// Draw horizontal line
|
|
GUI.DrawTexture(
|
|
new Rect(
|
|
centerX - crosshairSize / 2f,
|
|
centerY - crosshairThickness / 2f,
|
|
crosshairSize,
|
|
crosshairThickness
|
|
),
|
|
Texture2D.whiteTexture
|
|
);
|
|
|
|
// Draw vertical line
|
|
GUI.DrawTexture(
|
|
new Rect(
|
|
centerX - crosshairThickness / 2f,
|
|
centerY - crosshairSize / 2f,
|
|
crosshairThickness,
|
|
crosshairSize
|
|
),
|
|
Texture2D.whiteTexture
|
|
);
|
|
|
|
// Reset GUI color
|
|
GUI.color = Color.white;
|
|
}
|
|
}
|