Initial Project Commit
This commit is contained in:
@@ -1,22 +1,39 @@
|
||||
using UnityEngine;
|
||||
using RPG.Movement;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace RPG.Combat
|
||||
{
|
||||
{
|
||||
public class Fighter : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private float weaponRange = 2f;
|
||||
Transform target;
|
||||
private void Update()
|
||||
{
|
||||
if(target != null)
|
||||
if (target == null) return;
|
||||
if (!GetIsInRange())
|
||||
{
|
||||
GetComponent<Mover>().MoveTo(target.position);
|
||||
target = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
GetComponent<Mover>().Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private bool GetIsInRange()
|
||||
{
|
||||
return Vector3.Distance(transform.position, target.position) <= weaponRange;
|
||||
}
|
||||
|
||||
public void Attack(CombatTarget combatTarget)
|
||||
{
|
||||
target = combatTarget.transform;
|
||||
}
|
||||
public void Cancel()
|
||||
{
|
||||
target = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user