41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class LookInteract : MonoBehaviour
|
|
{
|
|
public float interactRange = 20f;
|
|
public Texture2D normalCursor;
|
|
public Texture2D interactCursor;
|
|
|
|
void Update()
|
|
{
|
|
if (MenuController.Instance.isPaused) return;
|
|
|
|
Ray ray = new Ray(Camera.main.transform.position,
|
|
Camera.main.transform.forward);
|
|
|
|
if (Physics.Raycast(ray, out RaycastHit hit, interactRange))
|
|
{
|
|
if (hit.collider.CompareTag("Button"))
|
|
{
|
|
Cursor.SetCursor(interactCursor, Vector2.zero, CursorMode.Auto);
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
hit.collider.SendMessage("OnLookInteract",
|
|
SendMessageOptions.DontRequireReceiver);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Cursor.SetCursor(normalCursor, new Vector2(16, 16), CursorMode.Auto);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Cursor.SetCursor(normalCursor, new Vector2(16, 16), CursorMode.Auto);
|
|
}
|
|
}
|
|
}
|