2022-06-12 20:14:11 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
public class HealthBar : MonoBehaviour
|
|
|
|
{
|
|
|
|
public Slider slider;
|
2022-11-14 22:22:08 +01:00
|
|
|
public float maxHealth;
|
|
|
|
public float health;
|
2022-12-18 19:19:57 +01:00
|
|
|
|
|
|
|
public Text displayText;
|
|
|
|
public float currentHealth;
|
|
|
|
public string maxHealthString;
|
|
|
|
public string currentHealthString;
|
|
|
|
|
2022-06-12 20:14:11 +02:00
|
|
|
public void SetMaxHealth(float health)
|
|
|
|
{
|
2022-11-14 22:22:08 +01:00
|
|
|
|
|
|
|
maxHealth = PlayerPrefs.GetFloat("maxHealth");
|
|
|
|
slider.maxValue = maxHealth;
|
2022-06-12 20:14:11 +02:00
|
|
|
}
|
|
|
|
|
2022-11-14 22:22:08 +01:00
|
|
|
//public void SetHealth(float health)
|
|
|
|
//{
|
|
|
|
// slider.value = health;
|
|
|
|
//}
|
|
|
|
|
|
|
|
void Update()
|
2022-06-12 20:14:11 +02:00
|
|
|
{
|
2022-11-14 22:22:08 +01:00
|
|
|
maxHealth = PlayerPrefs.GetFloat("maxHealth");
|
|
|
|
health = PlayerPrefs.GetFloat("health");
|
|
|
|
slider.maxValue = maxHealth;
|
2022-06-12 20:14:11 +02:00
|
|
|
slider.value = health;
|
2022-12-18 19:19:57 +01:00
|
|
|
|
|
|
|
currentHealth = PlayerPrefs.GetFloat("health");
|
|
|
|
maxHealthString = maxHealth.ToString();
|
|
|
|
currentHealthString = currentHealth.ToString();
|
|
|
|
displayText.text = currentHealthString + "/" + maxHealthString;
|
2022-11-14 22:22:08 +01:00
|
|
|
//SetExp(exp);
|
2022-06-12 20:14:11 +02:00
|
|
|
}
|
|
|
|
}
|