AbstractUnit for cross team compatibility
+ New folder in Scripts
This commit is contained in:
parent
385d8669b1
commit
f8e85d7134
18 changed files with 112 additions and 80 deletions
48
Assets/Scripts/UnitScripts/MinecraftUnit.cs
Normal file
48
Assets/Scripts/UnitScripts/MinecraftUnit.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class MinecraftUnit : AbstractUnit
|
||||
{
|
||||
[field: SerializeField] public Rigidbody Body { get; private set; }
|
||||
[field: SerializeField] public HealthHandler HealthHandler { get; private set; }
|
||||
[field: SerializeField] public AttackHandler AttackHandler { get; private set; }
|
||||
[field: SerializeField] public MovementHandler MovementHandler { get; private set; }
|
||||
|
||||
|
||||
|
||||
void OnValidate()
|
||||
{
|
||||
Debug.Assert(Body != null);
|
||||
Debug.Assert(HealthHandler != null);
|
||||
Debug.Assert(AttackHandler != null);
|
||||
Debug.Assert(MovementHandler != null);
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
if (IsTeamA)
|
||||
{
|
||||
GlobalsVariable.AliveUnitsTeamA.Add(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalsVariable.AliveUnitsTeamB.Add(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Abstract implementation for compatibility with other team
|
||||
|
||||
public override bool Attack()
|
||||
{
|
||||
return AttackHandler.Attack();
|
||||
}
|
||||
|
||||
public override void TakeDamage(float damage)
|
||||
{
|
||||
HealthHandler.TakeDamage(damage);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue