54 lines
1.3 KiB
C#
Raw Permalink Normal View History

2025-06-05 00:11:38 +05:00
using System.Collections.Generic;
2025-05-28 10:27:04 +05:00
using UnityEngine;
2025-06-05 00:11:38 +05:00
using UnityEngine.EventSystems;
using UnityEngine.UI;
2025-05-28 10:27:04 +05:00
public class CursorManager : MonoBehaviour
{
public static CursorManager Instance;
[Header("Cursor Textures")]
public Texture2D defaultCursor;
public Texture2D linkCursor;
[Header("Cursor Hotspot")]
public Vector2 hotspot = Vector2.zero;
2025-06-05 00:11:38 +05:00
public GraphicRaycaster raycaster;
public EventSystem eventSystem;
2025-05-28 10:27:04 +05:00
private void Awake()
{
Instance = this;
SetDefaultCursor();
}
2025-06-05 00:11:38 +05:00
void Update()
{
if (Input.GetMouseButtonDown(0))
{
PointerEventData pointerData = new PointerEventData(eventSystem)
{
position = Input.mousePosition
};
List<RaycastResult> results = new List<RaycastResult>();
raycaster.Raycast(pointerData, results);
foreach (RaycastResult result in results)
{
Debug.Log("Clicked UI: " + result.gameObject.name,result.gameObject);
}
}
}
2025-05-28 10:27:04 +05:00
public void SetDefaultCursor()
{
Cursor.SetCursor(defaultCursor, hotspot, CursorMode.Auto);
}
public void SetLinkCursor()
{
Cursor.SetCursor(linkCursor, hotspot, CursorMode.Auto);
}
}