Souljack/Assets/_Project/Scripts/PlayerUtils/PlayerUI.cs

53 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
namespace _Project.Scripts.PlayerUtils
{
public class PlayerUI : MonoBehaviour
{
[Header("Настройки Интерфейса")]
[SerializeField] private bool showSpeedometer = true;
private PlayerMovement movement;
private void Start()
{
// Берем ссылку на компонент передвижения через фасад Player
movement = Player.Instance.Movement;
}
private void OnGUI()
{
if (!showSpeedometer || movement == null) return;
// Читаем публичное свойство скорости (мы добавим его ниже)
float speed = movement.CurrentSpeed;
float csUnits = speed * 38.5f;
GUIStyle style = new GUIStyle
{
fontSize = 24,
fontStyle = FontStyle.Bold
};
string state = "";
// Настраиваем цвет и текст состояния
if (movement.IsSliding)
{
style.normal.textColor = Color.yellow;
state = " [SLIDE]";
}
else if (!movement.IsGrounded)
{
style.normal.textColor = Color.green;
state = " [AIR]";
}
else
{
style.normal.textColor = Color.white;
}
GUI.Label(new Rect(30, 30, 500, 50), $"Speed: {speed:F1} m/s ({csUnits:F0} u/s){state}", style);
}
}
}