Untitled
unknown
plain_text
a year ago
813 B
11
Indexable
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Health : MonoBehaviour
{
[SerializeField] private float currentHealth;
[SerializeField] private float maxHealth = 10;
public Slider healthSlider;
// Start is called before the first frame update
void Start()
{
currentHealth = maxHealth;
healthSlider.maxValue = maxHealth;
healthSlider.value = currentHealth;
}
// Update is called once per frame
void Update()
{
}
public void TakeDamage(float amount)
{
currentHealth -= amount;
healthSlider.value = currentHealth;
if (currentHealth <= 0)
{
Debug.Log("Game Over");
}
}
}
Editor is loading...
Leave a Comment