Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        currentHP = (int)Mathf.Round((float)playerController.GetHP() / maxHP * 10);
        Debug.Log("CurrentHP: " + currentHP);
        Debug.Log("PreviousHP: " + prevHP);
        if (currentHP < prevHP && currentHP >= 0)
        {
            for (int i = prevHP - 1; i > currentHP - 1; i--)
            {
                hearts[i].SetActive(false);
            }
        }
        else if (currentHP > prevHP && currentHP <= 10)
        {
            for (int i = prevHP - 1; i < currentHP - 1; i++)
            {
                hearts[i].SetActive(true);
            }
        }
        else if (currentHP == 10)
        {
            hearts[9].SetActive(true);
        }
        prevHP = currentHP;

        if (prevHP == 0)
        {
            prevHP++;
        }
    }
Ejemplo n.º 2
0
 // Start is called before the first frame update
 void Start()
 {
     playerController = player.GetComponent <PlayerController3D>();
     maxHP            = playerController.GetMaxHP();
     prevHP           = (int)Mathf.Round((float)playerController.GetHP() / maxHP * 10);
     Debug.Log("Init PrevHP: " + prevHP);
 }