Sorry for the many questions I feel I am getting my groove!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPG.Movement;
namespace RPG.Combat
{
public class Fighter : MonoBehaviour
{
[SerializeField] float weaponRange = 2f;
[SerializeField] float timeBetweenAttacks = 1f;
[SerializeField] float weaponDamage = 5f;
Transform target;
float timeSinceLastAttack = 0;
private void Update()
{
timeSinceLastAttack += Time.deltaTime;
bool isInRange = GetIsInRange();
if (target != null && isInRange)
{
GetComponent<Mover>().MoveTo(target.position);
}
else
{
GetComponent<Mover>().Stop();
AttackBehaviour();
}
}
private void AttackBehaviour()
{
if (timeSinceLastAttack > timeBetweenAttacks)
{
GetComponent<Animator>().SetTrigger("attack");
timeSinceLastAttack = 0;
}
}
void (Hit)
{
Health healthComponent = target.GetComponent<Health>();
healthComponent.TakeDamage(weaponDamage);
}
private bool GetIsInRange()
{
return Vector3.Distance(transform.position, target.position) < weaponRange;
}
public class Fighter : MonoBehaviour
{
public void Attack(CombatTarget combatTarget)
{
target = combatTarget.transform;
}
public void Cancel()
{
target = null;
}
}
}
It's probably another misplaced } but I can't for the life of me see where it is.