Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using Interactable;
using UnityEngine;
using UnityEngine.InputSystem;
public class InteractCursor : MonoBehaviour
{
private IInteractable m_currentInteractable;
private InputAction m_Interact;
private void Start()
{
m_Interact = InputSystem.actions.FindAction("Interact");
}
private void Update()
{
if (m_Interact.WasPerformedThisFrame())
{
m_currentInteractable?.OnInteract();
}
}
private void OnTriggerEnter(Collider other)
{
Debug.Log("Enter");
if (other.TryGetComponent(out SpriteRenderer sprite))
{
sprite.color = Color.blue;
}
if (other.TryGetComponent(out IInteractable interactable))
{
m_currentInteractable = interactable;
}
}
private void OnTriggerExit(Collider other)
{
if (other.TryGetComponent(out SpriteRenderer sprite))
{
sprite.color = Color.white;
}
}
}