Capacity + Health and Mana bars
This commit is contained in:
parent
b21d392ff6
commit
7d3b4ced0e
41 changed files with 1739 additions and 32 deletions
39
Assets/Scripts/UnitScripts/Capacities/BaseCapacity.cs
Normal file
39
Assets/Scripts/UnitScripts/Capacities/BaseCapacity.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class BaseCapacity : MonoBehaviour
|
||||
{
|
||||
[field: SerializeField] public float MaxMana { get; private set; }
|
||||
[field: SerializeField] public float Mana { get; private set; }
|
||||
protected float ManaCost;
|
||||
protected AbstractUnit _unit;
|
||||
|
||||
|
||||
|
||||
// Called every frame
|
||||
protected virtual bool CapacityCall()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AddMana(float manaAdd)
|
||||
{
|
||||
Mana = Mathf.Max(Mana + manaAdd, MaxMana);
|
||||
}
|
||||
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
_unit = GetComponent<AbstractUnit>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Mana >= ManaCost)
|
||||
{
|
||||
bool capacityLaunched = CapacityCall();
|
||||
if (capacityLaunched) Mana -= ManaCost;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: adbf6613bee8e8088b3389c62d61b845
|
33
Assets/Scripts/UnitScripts/Capacities/GolemDefense.cs
Normal file
33
Assets/Scripts/UnitScripts/Capacities/GolemDefense.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class GolemDefense : BaseCapacity
|
||||
{
|
||||
[SerializeField] private float armorGain;
|
||||
[SerializeField] private float buffTime;
|
||||
[SerializeField] private SphereCollider buffArea;
|
||||
|
||||
protected override bool CapacityCall()
|
||||
{
|
||||
Collider[] hitColliders = Physics.OverlapSphere(transform.position, buffArea.radius, buffArea.includeLayers);
|
||||
foreach (Collider target in hitColliders)
|
||||
{
|
||||
if (!target.CompareTag("Unit")) continue;
|
||||
AbstractUnit targetUnit = target.GetComponent<AbstractUnit>();
|
||||
if (targetUnit.IsTeamA == _unit.IsTeamA)
|
||||
{
|
||||
CoroutineManager.Instance.StartCoroutine(AddThenRemoveArmor(targetUnit));
|
||||
}
|
||||
}
|
||||
return hitColliders.Length > 0;
|
||||
}
|
||||
|
||||
private IEnumerator AddThenRemoveArmor(AbstractUnit targetUnit)
|
||||
{
|
||||
targetUnit.AddArmor(armorGain);
|
||||
yield return new WaitForSeconds(buffTime);
|
||||
targetUnit.RemoveArmor(armorGain);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1ca640aad27b1da9d87fdc4302aa0cd3
|
Loading…
Add table
Add a link
Reference in a new issue