Welcome to GEMENTAR TOUR PUO V2 Development Documentation. Enjoy your stay!

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
wiki:etc_prototyping [2022/08/16 00:03] – [Health] adminwiki:etc_prototyping [2022/08/16 00:05] (current) – [UIController] admin
Line 1: Line 1:
 +====== UIController ======
 +
 +{{ :wiki:image_2022-08-16_080412946.png?600 |}}
 +
 +<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>();
 +        _zombieGunController.sendEventToUI.AddListener(UpdateBulletCount);
 +
 +        _zombiePlayerController = FindObjectOfType<ZombiePlayerController>();
 +        _zombiePlayerController.sendEventToUI.AddListener(UpdateStaminaCount);
 +        _zombiePlayerController.onPlayerDied.AddListener(UpadatePlayerDied);
 +        initialStamina = _zombiePlayerController.runStamina;
 +
 +        _zombieHealth = _zombiePlayerController.gameObject.GetComponent<ZombieHealth>();
 +        _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, 0, 100)).ToString();
 +    }
 +
 +    private float initialStamina;
 +    private void UpdateStaminaCount(float x)
 +    {
 +        int staminaPercentage = Mathf.RoundToInt(Mathf.Clamp(x/initialStamina * 100, 0, 100));
 +        staminaCount.text = staminaPercentage.ToString() + "%";
 +    }
 +
 +    private void UpadatePlayerDied()
 +    {
 +
 +    }
 +
 +    public void UpdateCoinCount(int x)
 +    {
 +        coinCount.text = x.ToString();
 +    }
 +
 +
 +}
 +
 +
 +</code>
 ====== Health ====== ====== Health ======
 +
  
 <code CSharp | Health Script> <code CSharp | Health Script>

QR Code
QR Code wiki:etc_prototyping (generated for current page)
Hello World!
DokuWiki with monobook... rules!