this is a health script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class health : MonoBehaviour
{
public float Health = 100f;
public float damage = 10f;
public string Map;
public Text text;
public Slider slider;
public GameObject Respawn;
void start()
{
Respawn.SetActive(false);
Health = PlayerPrefs.GetFloat("Health");
}
void Update()
{
PlayerPrefs.SetFloat("Health", Health);
PlayerPrefs.Save();
text.text = "" + Health;
slider.value = Health;
if (Health <= 0)
{
Die();
}
}
public void OnTriggerEnter(Collider hit)
{
if (hit.GetComponent<Collider>().gameObject.tag == "zombie_L1")
{
Health -= 10f;
}
}
void Die()
{
Respawn.SetActive(true);
SceneManager.LoadScene(Map);
}
}