Files
3D-FPS/3D FPS/Assets/Scripts/Player/PlayerHealth.cs

47 lines
889 B
C#
Raw Normal View History

2024-12-09 23:16:34 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.UI;
using UnityEngine.UI;
using TMPro;
public class PlayerHealth : MonoBehaviour
{
[SerializeField] private float startingHealth;
private float health;
public TextMeshProUGUI healthMonitor;
public GameOverScreen gameOverScreen;
private int score = 0;
public float Health
{
get
{
return health;
}
set
{
health = value;
healthMonitor.text = "Health: " + health;
if(health <= 0f)
{
playerDestroy();
}
}
}
void Start()
{
Health = startingHealth;
}
private void playerDestroy()
{
gameOverScreen.TriggerScreen(score);
}
public void AddScore(int n)
{
score += n;
}
}