Skip to content

Instantly share code, notes, and snippets.

using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneLoadedListener : MonoBehaviour
{
private void Start()
{
SceneManager.sceneLoaded += HandleSceneLoaded;
}
using System;
using UnityEngine;
public class Health : MonoBehaviour
{
[SerializeField] private int startingHealth = 100;
private int currentHealth;
public event Action<float> OnHPPctChanged = delegate { };
using System;
using UnityEngine;
public class NPC : MonoBehaviour
{
[SerializeField] private ParticleSystem deathParticlePrefab;
public event Action OnNPCDied = delegate { };
internal void TakeDamage(int amount)
using System;
using UnityEngine;
public class NPC : MonoBehaviour
{
public event Action OnNPCDied = delegate { };
internal void TakeDamage(int amount)
{
GetComponent<Health>().TakeDamage(amount);
using System;
using UnityEngine;
public class Health : MonoBehaviour
{
[SerializeField] private int startingHealth = 100;
private int currentHealth;
public event Action<float> OnHPPctChanged = delegate { };
using UnityEngine;
public class NPC : MonoBehaviour
{
internal void TakeDamage(int amount)
{
GetComponent<Health>().TakeDamage(amount);
}
}
@unity3dcollege
unity3dcollege / HPBar.cs
Created December 29, 2016 06:41
Updated HPBar.cs
using UnityEngine;
using UnityEngine.UI;
public class HPBar : MonoBehaviour
{
private Slider slider;
private void Start()
{
slider = GetComponentInChildren<Slider>();
using UnityEngine;
public class NPCParticles : MonoBehaviour
{
[SerializeField] private ParticleSystem deathParticlePrefab;
private void Start()
{
GetComponent<Health>().OnDied += HandleNPCDied;
}
public interface IHealth
{
event System.Action<float> OnHPPctChanged;
event System.Action OnDied;
void TakeDamage(int amount);
}
using System;
using UnityEngine;
public class StandardHealth : MonoBehaviour, IHealth
{
[SerializeField] private int startingHealth = 100;
private int currentHealth;
public event Action<float> OnHPPctChanged = delegate { };