RiftMayhem/Assets/Scripts/Interactables/UIWithInteractable.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

81 lines
1.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIWithInteractable : Interactable
{
[Header("Events:")]
[SerializeField] private GameEvent onInteraction;
[SerializeField] private GameEvent onRelease;
[Header("Listeners:")]
[SerializeField] private GameEventListener onUIClosed;
bool isUIOpen = false;
Transform storedTransform;
protected override void Awake()
{
base.Awake();
onUIClosed.Response.AddListener(CloseInteraction);
}
public override void Interact(bool melee)
{
base.Interact(melee);
if (!melee) return;
isUIOpen = true;
onInteraction.Raise();
}
public override void OnFocused(Transform playerTransform, PlayerController playerController)
{
base.OnFocused(playerTransform, playerController);
storedTransform = playerTransform;
}
protected override void Update()
{
if (isFocus && !hasInteracted)
{
distance = Vector3.Distance(player.position, interactionTransform.position);
if (distance <= radius)
{
Interact(true);
hasInteracted = true;
Debug.Log("Board Interacted-Closeup");
}
else if (interactableWithRange)
{
if (distance <= rangedRadius)
{
Interact(false);
hasInteracted = true;
}
}
}
else if (isUIOpen)
{
distance = Vector3.Distance(storedTransform.position, interactionTransform.position);
if (distance >= radius)
{
OnDeFocus();
onRelease.Raise();
Debug.Log("Board Released");
}
}
}
private void CloseInteraction()
{
isUIOpen = false;
OnDeFocus();
}
}