You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PhishingAwarenessSimulation/Assets/Scripts/CursorManager.cs

54 lines
1.3 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
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;
public GraphicRaycaster raycaster;
public EventSystem eventSystem;
private void Awake()
{
Instance = this;
SetDefaultCursor();
}
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);
}
}
}
public void SetDefaultCursor()
{
Cursor.SetCursor(defaultCursor, hotspot, CursorMode.Auto);
}
public void SetLinkCursor()
{
Cursor.SetCursor(linkCursor, hotspot, CursorMode.Auto);
}
}