Skip to content
Snippets Groups Projects
Commit 7697d2e9 authored by Jacky Chen's avatar Jacky Chen
Browse files

Added Health for Player - Code

parent 562c31ee
No related branches found
No related tags found
No related merge requests found
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HealthStat : MonoBehaviour
{
private Image content;
[SerializeField]
private Text statValue;
[SerializeField]
private float LerpSpeed;
private float currentFill;
public float MyMaxValue { get; set; }
private float currentValue;
public float MyCurrentValue
{
get
{
return currentValue;
}
set
{
if (value > MyMaxValue)
{
currentValue = MyMaxValue;
}
else if (value < 0)
{
currentValue = 0;
}
else
{
currentValue = value;
}
currentFill = currentValue / MyMaxValue;
statValue.text = currentValue + "/" + MyMaxValue;
}
}
// Start is called before the first frame update
void Start()
{
content = GetComponent<Image>();
}
// Update is called once per frame
void Update()
{
if (currentFill != content.fillAmount)
{
content.fillAmount = Mathf.Lerp(content.fillAmount, currentFill, Time.deltaTime * LerpSpeed);
}
}
public void Initialize(float currentValue, float maxValue)
{
MyMaxValue = maxValue;
MyCurrentValue = currentValue;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment