feat: Event & Teleporter

This commit is contained in:
2026-11-03 22:58:10 +01:00
parent a7e8ef1a1f
commit 9fd4e13d34
34 changed files with 5877 additions and 25 deletions

View File

@@ -4,7 +4,7 @@ using UnityEngine;
namespace Arena.Combat
{
/// <summary>
/// Hit points of an entity. Serialized inside the component that owns it (Player, Enemy),
/// Health points of an entity. Serialized inside the component that owns it (Player, Enemy),
/// which calls Initialize in its Awake.
/// </summary>
[System.Serializable]
@@ -12,19 +12,19 @@ namespace Arena.Combat
{
#region Fields
[Tooltip("Hit points when full.")]
[Tooltip("Health points when full.")]
[Min(1)] public int Max = 100;
[Tooltip("Current hit points, visible for debugging.")]
[Tooltip("Current health points, visible for debugging.")]
[SerializeField] private int _current;
/// <summary>
/// Raised with the current and max hit points each time they change.
/// Raised with the current and max health points each time they change.
/// </summary>
public event Action<int, int> OnChange;
/// <summary>
/// Raised once, when the hit points reach zero.
/// Raised once, when the health points reach zero.
/// </summary>
public event Action OnDied;
@@ -36,7 +36,7 @@ namespace Arena.Combat
#region Public Methods
/// <summary>
/// Fills the hit points. Called by the owner in its Awake.
/// Fills the health points. Called by the owner in its Awake.
/// </summary>
public void Initialize()
{
@@ -44,7 +44,7 @@ namespace Arena.Combat
}
/// <summary>
/// Removes hit points and raises OnDied the first time they reach zero.
/// Removes health points and raises OnDied the first time they reach zero.
/// </summary>
public void TakeDamage(int amount)
{
@@ -58,7 +58,7 @@ namespace Arena.Combat
}
/// <summary>
/// Gives hit points back without exceeding Max. Has no effect once dead.
/// Gives health points back without exceeding Max. Has no effect once dead.
/// </summary>
public void Heal(int amount)
{

View File

@@ -0,0 +1,68 @@
using UnityEngine;
namespace Arena.Combat
{
/// <summary>
/// Moves straight ahead and damages the first IDamageable it touches.
/// Needs a trigger collider and a kinematic Rigidbody.
/// </summary>
[RequireComponent(typeof(Rigidbody))]
public class Projectile : MonoBehaviour
{
[System.Serializable]
public class Settings
{
[Tooltip("Speed, in meters per second.")]
[Min(0f)] public float Speed = 20f;
[Tooltip("Time before an unused projectile is destroyed, in seconds.")]
[Min(0.1f)] public float Lifetime = 2f;
}
#region Fields
[SerializeField] private Settings _settings;
private int _damage;
private GameObject _owner;
#endregion
#region Unity Lifecycle
private void Update()
{
transform.position += transform.forward * _settings.Speed * Time.deltaTime;
}
private void OnTriggerEnter(Collider other)
{
// Ignore the shooter and the other trigger zones
if (other.isTrigger || other.gameObject == _owner)
return;
if (other.TryGetComponent(out IDamageable target))
target.TakeDamage(_damage);
Destroy(gameObject);
}
#endregion
#region Public Methods
/// <summary>
/// Starts the projectile. Called right after Instantiate by whoever fires it.
/// </summary>
/// <param name="damage">Damage dealt to the IDamageable it touches.</param>
/// <param name="owner">Shooter, ignored by the projectile.</param>
public void Launch(int damage, GameObject owner)
{
_damage = damage;
_owner = owner;
Destroy(gameObject, _settings.Lifetime);
}
#endregion
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 875f6e6257f7027489dceee7bdfec3cb

View File

@@ -0,0 +1,16 @@
using UnityEngine;
public class ProjectileLauncher : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 4bb53e2fd0884a746883755fca366194