Answers for "unity healthbar"

C#
1

unity healthbar

using System.Collections.Generic;
using UnityEngine;

public class Health : MonoBehaviour
{
    public int curHealth = 0;
    public int maxHealth = 100;

    public HealthBar healthBar;

    void Start()
    {
        curHealth = maxHealth;
    }

    void Update()
    {
        if( Input.GetKeyDown( KeyCode.Space ) )
        {
            DamagePlayer(10);
        }
    }

    public void DamagePlayer( int damage )
    {
        curHealth -= damage;

        healthBar.SetHealth( curHealth );
    }
}
https://weeklyhow.com/how-to-make-a-health-bar-in-unity/
Posted by: Guest on August-25-2021

C# Answers by Framework

Browse Popular Code Answers by Language