-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInteractable.cs
66 lines (49 loc) · 1.3 KB
/
Interactable.cs
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using UnityEngine;
public class Interactable : MonoBehaviour {
public float radius = 4f;
public Transform interactionTransform;
bool isFocus = false;
Transform player;
bool hasInteracted = false;
public virtual void Interact()
{
// This method is meant to be overwritten
//Debug.Log("Interacting with " + transform.name);
}
void Update()
{
if (isFocus && !hasInteracted)
{
float distance = Vector3.Distance(player.position, interactionTransform.position);
if (distance <= radius)
{
Interact();
hasInteracted = true;
}
}
}
public void OnFocus (Transform playerTransform)
{
isFocus = true;
player = playerTransform;
hasInteracted = false;
}
public void OnDefocus()
{
isFocus = false;
player = null;
hasInteracted = false;
}
private void OnDrawGizmosSelected()
{
if(interactionTransform == null)
{
interactionTransform = transform;
}
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(interactionTransform.position, radius);
}
public virtual void Die()
{
}
}