public void Attack(_CharacterStat targetStat) { if (attackCoolDown <= 0) { opponentStat = targetStat; opponentStat.TakeDamage(myStat.damage.GetValue()); if (OnAttack != null) { OnAttack(); } attackCoolDown = 1f / attackSpeed; inCombat = true; lastAttackTime = Time.time; } }
void Update() { float distance = Vector3.Distance(transform.position, player.position); if (distance <= lookRadius) { agent.SetDestination(player.position); if (distance <= agent.stoppingDistance) { _CharacterStat targetStat = player.GetComponent <_CharacterStat> (); if (targetStat != null) { combat.Attack(targetStat); } FaceToTarget(); } } }
void Start() { myStat = GetComponent <_CharacterStat> (); }