ProjetAMJV_CR/Assets/Scripts/UnitScripts/BehaviorState/AbstractBehaviour.cs
2025-01-28 04:11:53 +01:00

47 lines
1.2 KiB
C#

using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[RequireComponent(typeof(MinecraftUnit))]
[RequireComponent(typeof(MovementHandler))]
public abstract class AbstractBehaviour : MonoBehaviour
{
[SerializeField] private float pathFps = 1.0f;
[SerializeField] private float attackFps = 5.0f;
protected abstract void MoveAction();
protected abstract void AttackAction();
protected MinecraftUnit CurrentMinecraftUnit;
void Start()
{
CurrentMinecraftUnit = GetComponent<MinecraftUnit>();
StartCoroutine(attackUpdate());
StartCoroutine(pathUpdate());
}
// Path update and attack update can be expansive, so we don't do that every frame. We create custom update
// We create custom update at low fps to handle this without performance issues
private IEnumerator attackUpdate()
{
while (true)
{
AttackAction();
yield return new WaitForSeconds(1.0f/attackFps);
}
}
private IEnumerator pathUpdate()
{
while (true)
{
MoveAction();
yield return new WaitForSeconds(1.0f/pathFps);
}
}
}