just wanted to show how I coded this lecture during the challenge, I think it’s a bit cleaner than @sampattuzzi 's solution. Someone tell me if I’m crazy…as I am a novice…
using RPG.Movement;
using UnityEngine;
namespace RPG.Combat
{
public class Fighter : MonoBehaviour
{
// SHIPPING DATA //
// CHANGING DATA //
Transform target;
Mover moverScript;
[SerializeField] float weaponRange = 2f;
// * CODE * //
void Start()
{
moverScript = GetComponent<Mover>();
}
void Update()
{
if (target != null)
{
MoveToAttack();
}
}
private void MoveToAttack()
{
moverScript.MoveToTarget(target.position);
if (Vector3.Distance(target.position, transform.position) <= weaponRange)
{
moverScript.StopMovement();
}
}
public void Attack(CombatTarget combatTarget)
{
target = combatTarget.transform;
print("take that " + combatTarget + " you flat faced heathen!");
}
public void StopAttacking()
{
target = null;
}
}
}