Skip to content

Instantly share code, notes, and snippets.

View NPC.cs
using System;
using UnityEngine;
public class NPC : MonoBehaviour
{
[SerializeField] private int startingHp = 100;
[SerializeField] private ParticleSystem deathParticlePrefab;
private int currentHp;
View NPCParticles.cs
using UnityEngine;
public class NPCParticles : MonoBehaviour
{
[SerializeField] private ParticleSystem deathParticlePrefab;
private void Start()
{
GetComponent<NPC>().OnNPCDied += HandleNPCDied;
}
View SRP - NPC.cs
using System;
using UnityEngine;
public class NPC : MonoBehaviour
{
[SerializeField]
private int startingHp = 100;
[SerializeField]
private ParticleSystem deathParticlePrefab;
View SRP - HPBar.cs
using UnityEngine;
using UnityEngine.UI;
public class HPBar : MonoBehaviour
{
private Slider _slider;
private void Start()
{
_slider = GetComponentInChildren<Slider>();
View NPC.cs - With Particles!
using System;
using UnityEngine;
public class NPC : MonoBehaviour
{
[SerializeField]
private int startingHp = 100;
[SerializeField]
private UnityEngine.UI.Slider hpBarSlider;
[SerializeField]
View NPC.cs
using System;
using UnityEngine;
public class NPC : MonoBehaviour
{
[SerializeField]
private int _startingHp = 100;
[SerializeField]
private UnityEngine.UI.Slider _hpBarSlider;
View TransformHelper.GetDirection
public Vector3 TransformHelper.GetDirection(Transform source, Transform destination);
View DirectionTo
var direction = sourceTransform.DirectionTo(destinationTransform);
View GetDirection
var direction = MyReallyBadlyNamedHelperClass.GetDirection(sourceTransform.position, destinationTransform.position);
View TransformExtensions.cs - LookAtY - Full
public static void LookAtY(this Transform transform, Vector3 point)
{
var lookPos = point - transform.position;
lookPos.y = 0;
var rotation = Quaternion.LookRotation(lookPos);
transform.rotation = rotation;
}
You can’t perform that action at this time.