Basic game completed
This commit is contained in:
46
3D FPS/Assets/Scripts/Player/PlayerHealth.cs
Normal file
46
3D FPS/Assets/Scripts/Player/PlayerHealth.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user