44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
using UnityEngine;
|
|
|
|
/// <summary>Масляный щуп: при наведении показывает уровень и состояние моторного масла.</summary>
|
|
public class OilDipstick : MonoBehaviour, IInteractable
|
|
{
|
|
private CarFluids fluids;
|
|
private Vector3 restLocalPos;
|
|
private float pulledTimer;
|
|
|
|
private void Awake()
|
|
{
|
|
fluids = GetComponentInParent<CarFluids>();
|
|
restLocalPos = transform.localPosition;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (pulledTimer > 0f) pulledTimer -= Time.deltaTime;
|
|
Vector3 target = restLocalPos + (pulledTimer > 0f ? Vector3.up * 0.14f : Vector3.zero);
|
|
transform.localPosition = Vector3.Lerp(transform.localPosition, target, Time.deltaTime * 8f);
|
|
}
|
|
|
|
public string GetPrompt()
|
|
{
|
|
if (fluids == null) fluids = GetComponentInParent<CarFluids>();
|
|
if (fluids == null) return "Масляный щуп";
|
|
|
|
CarFluids.FluidReservoir oil = fluids.EngineOil;
|
|
int level = Mathf.RoundToInt(oil.FillPercent * 100f);
|
|
int quality = Mathf.RoundToInt(oil.quality * 100f);
|
|
string qText = oil.currentLiters < 0.05f ? "масла нет!" : oil.QualityText;
|
|
string color = (oil.FillPercent < 0.5f || oil.quality < 0.5f) ? "#E5534B" : "#4CD07D";
|
|
return $"Масляный щуп [E] — вытащить\n<color={color}>Уровень: {level}% | Состояние: {quality}% ({qText})</color>";
|
|
}
|
|
|
|
public void Interact(GameObject interactor)
|
|
{
|
|
pulledTimer = 2.5f;
|
|
CarOwnership own = CarOwnership.Get(gameObject);
|
|
if (own != null) own.hoodInspected = true;
|
|
ProceduralAudioManager.Instance?.Play(SfxId.Pickup, transform.position, 0.6f);
|
|
}
|
|
}
|