59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
using UnityEngine;
|
|
using RaycastPro;
|
|
using RaycastPro.RaySensors;
|
|
using StarterAssets;
|
|
using Unity.VisualScripting;
|
|
|
|
public class InteractionManager : MonoBehaviour
|
|
{
|
|
StarterAssetsInputs starterAssetsInputs;
|
|
[SerializeField] GameObject player;
|
|
[SerializeField] PopUpManager popUpManager;
|
|
GameObject currentInteractable;
|
|
[SerializeField] BasicRay interactionRay;
|
|
|
|
void Awake()
|
|
{
|
|
starterAssetsInputs = player.GetComponent<StarterAssetsInputs>();
|
|
}
|
|
void Update()
|
|
{
|
|
if(starterAssetsInputs.interact)
|
|
{
|
|
TriggerInteraction();
|
|
}
|
|
}
|
|
|
|
public void TriggerInteraction()
|
|
{
|
|
bool isPopUpActive = popUpManager.IsPopUpActive();
|
|
|
|
if (isPopUpActive && currentInteractable != null)
|
|
{
|
|
currentInteractable.GetComponent<IInteract>()?.OnInteract();
|
|
}
|
|
starterAssetsInputs.InteractInput(false); // Reset the interact input after handling
|
|
}
|
|
public void AssignInteractable()
|
|
{
|
|
currentInteractable = interactionRay.Hit.transform.gameObject;
|
|
popUpManager.ShowPopUp();
|
|
}
|
|
public void ClearInteractable()
|
|
{
|
|
currentInteractable = null;
|
|
popUpManager.HidePopUp();
|
|
}
|
|
|
|
public void CheckLights()
|
|
{
|
|
if(currentInteractable != null)
|
|
{
|
|
Light light = currentInteractable.GetComponent<Light>();
|
|
if (light != null)
|
|
{
|
|
Debug.Log("Interacted with a light: " + light.name);
|
|
}
|
|
}
|
|
}
|
|
} |