Files
3D-FPS/3D FPS/Assets/Scripts/Player/PlayerHealth.cs
Michal Sedlák ff4ef835f2 edited script and builded first build
Removed unity editor so it can be builded
2024-12-10 00:05:34 +01:00

46 lines
867 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
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;
}
}