Skip to content

Instantly share code, notes, and snippets.

@Hellhackee
Created January 15, 2021 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hellhackee/686e4778507b97d72eb1d55b59d286d2 to your computer and use it in GitHub Desktop.
Save Hellhackee/686e4778507b97d72eb1d55b59d286d2 to your computer and use it in GitHub Desktop.
Lesson UI (script player)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class Player : MonoBehaviour
{
[SerializeField] private int _maxHealth;
private int _health;
public event UnityAction<int, int> HealthChanged;
private void Start()
{
_health = _maxHealth;
HealthChanged?.Invoke(_health, _maxHealth);
}
public void ChangeHealth(int health)
{
int changedHealth = _health + health;
if (changedHealth > _maxHealth || changedHealth < 0)
return;
_health = changedHealth;
HealthChanged?.Invoke(_health, _maxHealth);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment