RiftMayhem/Assets/Scripts/Interactable.cs
Pedro Gomes d12942bff4 World Jobs Listing Board interactable
Whole interactable world-board with different zones and jobs ready to be completed.

- party voting for job selection & scene swapping
- fully working scene change between inn and skellyard
- updated many systems with lots of new information
- bunch of new UIs to acomodate new job and scene swapping voting systems
2024-05-13 01:15:58 +01:00

84 lines
2.0 KiB
C#

using UnityEngine;
using UnityEditor;
public class Interactable : MonoBehaviour
{
public float radius = 3f;
public bool interactableWithRange = false;
public float rangedRadius = 10f;
public Transform interactionTransform;
protected bool isFocus = false;
protected Transform player;
protected PlayerController playerController;
protected bool hasInteracted = false;
protected float distance;
protected virtual void Awake()
{
gameObject.layer = 10; //interactable layer
}
public virtual void Interact(bool melee)
{
//this method is meant to be overwritten
//Debug.Log("Interacting with: " + transform.name);
}
protected virtual void Update()
{
if (isFocus && !hasInteracted)
{
distance = Vector3.Distance(player.position, interactionTransform.position);
if (distance <= radius)
{
Interact(true);
hasInteracted = true;
}
else if (interactableWithRange)
{
if (distance <= rangedRadius)
{
Interact(false);
hasInteracted = true;
}
}
}
}
public virtual void OnFocused(Transform playerTransform, PlayerController playerController)
{
isFocus = true;
player = playerTransform;
this.playerController = playerController;
hasInteracted = false;
}
public virtual 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);
if (interactableWithRange)
{
Gizmos.color = Color.magenta;
Gizmos.DrawWireSphere(interactionTransform.position, rangedRadius);
}
}
}