46 lines
1.7 KiB
C#
46 lines
1.7 KiB
C#
using UnityEngine;
|
|
|
|
/// <summary>Касса магазина автохимии на АЗС или ноутбук в гараже: [E] открывает магазин и склад.</summary>
|
|
public class ShopCounter : MonoBehaviour, IInteractable
|
|
{
|
|
[SerializeField] private Transform deliveryPoint;
|
|
[SerializeField] private string title = "Магазин автохимии и запчастей";
|
|
[SerializeField] private float nearbyRadius = 4f;
|
|
|
|
public static ShopCounter PlayerNearby { get; private set; }
|
|
public Transform DeliveryPoint => deliveryPoint;
|
|
|
|
private Transform player;
|
|
|
|
public void Configure(Transform delivery, string newTitle)
|
|
{
|
|
deliveryPoint = delivery;
|
|
title = newTitle;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (player == null)
|
|
{
|
|
PlayerMovement pm = FindAnyObjectByType<PlayerMovement>();
|
|
if (pm != null) player = pm.transform;
|
|
}
|
|
bool near = player != null && player.gameObject.activeInHierarchy && Vector3.Distance(player.position, transform.position) < nearbyRadius;
|
|
if (near) PlayerNearby = this;
|
|
else if (PlayerNearby == this) PlayerNearby = null;
|
|
}
|
|
|
|
public string GetPrompt() => $"[E] {title} (также клавиша K)";
|
|
|
|
public void Interact(GameObject interactor)
|
|
{
|
|
GameEconomyManager eco = GameEconomyManager.Instance;
|
|
if (eco != null && !eco.DiplomaFeatures)
|
|
{
|
|
GameHUD.Notify("Магазин доступен в Дипломной версии", GameUI.Muted);
|
|
return;
|
|
}
|
|
if (GarageWarehouseUI.Instance != null) GarageWarehouseUI.Instance.Open(deliveryPoint);
|
|
}
|
|
}
|