full playable game

This commit is contained in:
MrTorex committed 2026-02-24 09:18:49 +03:00
1 parent afcd8761e6
commit 1869fa7584
56 files changed
+7581 -37

No files matched your search

+87
View File
@@ -0,0 +1,87 @@
using TMPro;
using UnityEngine;
using Code.Gameplay.Character.Core;
using Code.Gameplay.Character.Inventory;
using Code.Gameplay.Character.Stats;
namespace Code.UI
{
public class GameUI : MonoBehaviour
{
[SerializeField] private TMP_Text weaponNameText;
[SerializeField] private TMP_Text healthText;
[SerializeField] private TMP_Text ammoText;
[SerializeField] private string weaponNameFormat = "CURRENT WEAPON: {0}";
[SerializeField] private string healthFormat = "HP: {0}/{1}";
[SerializeField] private string ammoFormat = "AMMO: {0}/{1}";
private CharacterProvider _player;
private HealthSystem _playerHealth;
private WeaponInventory _weaponInventory;
private void Start()
{
_player = FindFirstObjectByType<CharacterProvider>();
if (_player != null)
{
_playerHealth = _player.GetComponent<HealthSystem>();
_weaponInventory = _player.GetComponent<WeaponInventory>();
}
if (_playerHealth != null)
{
_playerHealth.OnHealthChanged += UpdateHealth;
}
}
private void Update()
{
UpdateWeaponName();
UpdateHealth();
UpdateAmmo();
}
private void UpdateWeaponName()
{
if (weaponNameText == null || _weaponInventory?.CurrentWeapon == null) return;
var weaponName = _weaponInventory.CurrentWeapon.WeaponName;
weaponNameText.text = string.Format(weaponNameFormat, weaponName.ToUpper());
}
private void UpdateHealth()
{
if (healthText == null || _playerHealth == null) return;
healthText.text = string.Format(healthFormat,
_playerHealth.CurrentHealth,
_playerHealth.MaxHealth);
}
private void UpdateHealth(float current, float max)
{
if (healthText == null) return;
healthText.text = string.Format(healthFormat, current, max);
}
private void UpdateAmmo()
{
if (ammoText == null || _weaponInventory?.CurrentWeapon == null) return;
var weapon = _weaponInventory.CurrentWeapon;
ammoText.text = string.Format(ammoFormat,
weapon.CurrentAmmo,
weapon.ReserveAmmo);
}
private void OnDestroy()
{
if (_playerHealth != null)
{
_playerHealth.OnHealthChanged -= UpdateHealth;
}
}
}
}