механики
This commit is contained in:
1 parent
dd5a95a4d3
commit
11d57bec19
129 files changed
+21889
-62
No files matched your search
@@ -0,0 +1,127 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PlayerAmmoUI : MonoBehaviour
|
||||
{
|
||||
[Header("Ссылки")]
|
||||
public PlayerGun playerGun;
|
||||
public Text ammoText;
|
||||
public Text statusText;
|
||||
public Image ammoIcon;
|
||||
|
||||
[Header("Цвета")]
|
||||
public Color normalColor = Color.white;
|
||||
public Color lowAmmoColor = new Color(1f, 0.6f, 0.1f, 1f); // Оранжевый при малом запасе
|
||||
public Color noAmmoColor = new Color(0.95f, 0.2f, 0.2f, 1f); // Красный когда пусто
|
||||
public Color reloadingColor = new Color(1f, 0.85f, 0.2f, 1f); // Желтый при перезарядке
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (playerGun == null)
|
||||
{
|
||||
playerGun = FindAnyObjectByType<PlayerGun>();
|
||||
}
|
||||
|
||||
UpdateAmmoUI();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
UpdateAmmoUI();
|
||||
}
|
||||
|
||||
private void UpdateAmmoUI()
|
||||
{
|
||||
if (playerGun == null)
|
||||
{
|
||||
playerGun = FindAnyObjectByType<PlayerGun>();
|
||||
if (playerGun == null) return;
|
||||
}
|
||||
|
||||
bool isEquipped = playerGun.IsEquipped;
|
||||
int current = playerGun.CurrentAmmo;
|
||||
int reserve = playerGun.ReserveAmmo;
|
||||
bool reloading = playerGun.IsReloading;
|
||||
|
||||
// Если оружие убрано (в руках кулаки)
|
||||
if (!isEquipped)
|
||||
{
|
||||
if (ammoIcon != null)
|
||||
{
|
||||
ammoIcon.color = new Color(1f, 1f, 1f, 0.35f);
|
||||
}
|
||||
|
||||
if (ammoText != null)
|
||||
{
|
||||
ammoText.text = "КУЛАКИ";
|
||||
ammoText.color = normalColor;
|
||||
}
|
||||
|
||||
if (statusText != null)
|
||||
{
|
||||
statusText.gameObject.SetActive(true);
|
||||
statusText.text = "[2] ВЗЯТЬ ОРУЖИЕ";
|
||||
statusText.color = normalColor;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Оружие в руках (огнестрел активен)
|
||||
if (ammoIcon != null)
|
||||
{
|
||||
ammoIcon.color = Color.white;
|
||||
}
|
||||
|
||||
// Обновление основного текста
|
||||
if (ammoText != null)
|
||||
{
|
||||
ammoText.text = $"{current} / {reserve}";
|
||||
|
||||
if (reloading)
|
||||
{
|
||||
ammoText.color = reloadingColor;
|
||||
}
|
||||
else if (current == 0)
|
||||
{
|
||||
ammoText.color = noAmmoColor;
|
||||
}
|
||||
else if (current <= 2)
|
||||
{
|
||||
ammoText.color = lowAmmoColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
ammoText.color = normalColor;
|
||||
}
|
||||
}
|
||||
|
||||
// Обновление статуса (перезарядка / подсказка / убрать в кобуру)
|
||||
if (statusText != null)
|
||||
{
|
||||
if (reloading)
|
||||
{
|
||||
statusText.gameObject.SetActive(true);
|
||||
statusText.text = "ПЕРЕЗАРЯДКА...";
|
||||
statusText.color = reloadingColor;
|
||||
}
|
||||
else if (current == 0 && reserve > 0)
|
||||
{
|
||||
statusText.gameObject.SetActive(true);
|
||||
statusText.text = "[R] ПЕРЕЗАРЯДИТЬ";
|
||||
statusText.color = noAmmoColor;
|
||||
}
|
||||
else if (current == 0 && reserve == 0)
|
||||
{
|
||||
statusText.gameObject.SetActive(true);
|
||||
statusText.text = "НЕТ ПАТРОНОВ!";
|
||||
statusText.color = noAmmoColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
statusText.gameObject.SetActive(true);
|
||||
statusText.text = "[1] УБРАТЬ ОРУЖИЕ";
|
||||
statusText.color = new Color(0.85f, 0.85f, 0.85f, 0.75f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user