Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| wiki:etc_prototyping [2022/08/15 23:47] – created admin | wiki:etc_prototyping [2022/08/16 00:05] (current) – [UIController] admin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== UIController ====== | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | <code CSharp | UI Controller Script> | ||
| + | using System.Collections; | ||
| + | using System.Collections.Generic; | ||
| + | using UnityEngine; | ||
| + | using TMPro; | ||
| + | |||
| + | public class ZombieUIManager : MonoBehaviour | ||
| + | { | ||
| + | public TextMeshProUGUI bulletCount; | ||
| + | public TextMeshProUGUI staminaCount; | ||
| + | public TextMeshProUGUI healthCount; | ||
| + | public TextMeshProUGUI coinCount; | ||
| + | private ZombieGunController _zombieGunController; | ||
| + | private ZombiePlayerController _zombiePlayerController; | ||
| + | private ZombieHealth _zombieHealth; | ||
| + | |||
| + | |||
| + | private void Awake() | ||
| + | { | ||
| + | _zombieGunController = FindObjectOfType< | ||
| + | _zombieGunController.sendEventToUI.AddListener(UpdateBulletCount); | ||
| + | |||
| + | _zombiePlayerController = FindObjectOfType< | ||
| + | _zombiePlayerController.sendEventToUI.AddListener(UpdateStaminaCount); | ||
| + | _zombiePlayerController.onPlayerDied.AddListener(UpadatePlayerDied); | ||
| + | initialStamina = _zombiePlayerController.runStamina; | ||
| + | |||
| + | _zombieHealth = _zombiePlayerController.gameObject.GetComponent< | ||
| + | _zombieHealth.sendEventHealthCount.AddListener(UpdateHealth); | ||
| + | } | ||
| + | |||
| + | private void UpdateBulletCount(int x) | ||
| + | { | ||
| + | bulletCount.text = x.ToString(); | ||
| + | } | ||
| + | |||
| + | private void UpdateHealth(float x) | ||
| + | { | ||
| + | healthCount.text = Mathf.Ceil(Mathf.Clamp(x, | ||
| + | } | ||
| + | |||
| + | private float initialStamina; | ||
| + | private void UpdateStaminaCount(float x) | ||
| + | { | ||
| + | int staminaPercentage = Mathf.RoundToInt(Mathf.Clamp(x/ | ||
| + | staminaCount.text = staminaPercentage.ToString() + " | ||
| + | } | ||
| + | |||
| + | private void UpadatePlayerDied() | ||
| + | { | ||
| + | |||
| + | } | ||
| + | |||
| + | public void UpdateCoinCount(int x) | ||
| + | { | ||
| + | coinCount.text = x.ToString(); | ||
| + | } | ||
| + | |||
| + | |||
| + | } | ||
| + | |||
| + | |||
| + | </ | ||
| + | ====== Health ====== | ||
| + | |||
| + | |||
| + | <code CSharp | Health Script> | ||
| + | using Sirenix.OdinInspector; | ||
| + | using System.Collections; | ||
| + | using System.Collections.Generic; | ||
| + | using UnityEngine; | ||
| + | using UnityEngine.Events; | ||
| + | |||
| + | public class ZombieHealth : MonoBehaviour | ||
| + | { | ||
| + | [HideInEditorMode] | ||
| + | public UnityEvent sendEventOnMinusHealth; | ||
| + | |||
| + | [HideInEditorMode] | ||
| + | public UnityEvent< | ||
| + | |||
| + | |||
| + | [SerializeField] | ||
| + | public float _health { get; private set; } = 100f; | ||
| + | |||
| + | private void Start() | ||
| + | { | ||
| + | sendEventHealthCount.Invoke(_health); | ||
| + | } | ||
| + | |||
| + | public bool IsDead() | ||
| + | { | ||
| + | if(_health <= 0f) | ||
| + | { | ||
| + | return true; | ||
| + | } | ||
| + | |||
| + | return false; | ||
| + | } | ||
| + | |||
| + | public void MinusHealth(float x) | ||
| + | { | ||
| + | _health -= x; | ||
| + | sendEventOnMinusHealth.Invoke(); | ||
| + | sendEventHealthCount.Invoke(_health); | ||
| + | } | ||
| + | |||
| + | [Button] | ||
| + | public void FullHealth() | ||
| + | { | ||
| + | _health = 100f; | ||
| + | } | ||
| + | |||
| + | [Button] | ||
| + | public void EmptyHealth() | ||
| + | { | ||
| + | _health = -1f; | ||
| + | } | ||
| + | |||
| + | |||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| ====== Coin ====== | ====== Coin ====== | ||