add basic dialogue system and interactable interface
This commit is contained in:
@@ -4,6 +4,8 @@ public class PlayerController : MonoBehaviour
|
||||
{
|
||||
public GameObject DougBody;
|
||||
public float walkSpeed;
|
||||
|
||||
Interactable nearestInteractable;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
@@ -16,6 +18,7 @@ void Update()
|
||||
{
|
||||
RotatePlayerTowardMouse();
|
||||
Walk();
|
||||
TryInteract();
|
||||
}
|
||||
|
||||
void Walk()
|
||||
@@ -33,4 +36,37 @@ void RotatePlayerTowardMouse()
|
||||
|
||||
DougBody.transform.rotation = Quaternion.Euler(new Vector3(0f, -(angle + 90), 0f));
|
||||
}
|
||||
|
||||
void TryInteract()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.E) && nearestInteractable != null)
|
||||
{
|
||||
nearestInteractable.Interact();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
Interactable interactable = other.GetComponent<Interactable>();
|
||||
|
||||
// store nearest interactable if it exists
|
||||
if (interactable != null)
|
||||
{
|
||||
nearestInteractable = interactable;
|
||||
interactable.MoveInsideRange();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
// just null out interactables when we leave an interactable trigger (we cant and shouldn't overlap interactables)
|
||||
Interactable interactable = other.GetComponent<Interactable>();
|
||||
|
||||
// store nearest interactable if it exists
|
||||
if (interactable != null)
|
||||
{
|
||||
nearestInteractable.MoveOutsideRange();
|
||||
nearestInteractable = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user