My Atttack Challenge

Lecture Ref: 5_IN_RPG

I think i am getting Somewhere as My code is working as i expected :slight_smile: that’s how my Attack challenge went. player is getting chased by the enemy and getting damage if i am in the range and if the enemy is death he is not chasing me anymore. Please tell me . Is there anything that can broke my code in the future or any issues going with this approach. Thank You.

using UnityEngine;
using RPG.Combat;
using RPG.Movement;
namespace RPG.Control
{
public class AIController : MonoBehaviour
{
[SerializeField] float chaseDistance = 5f;

    private void Update()
    {
        if (DistanceToPlayer() < chaseDistance && !transform.gameObject.GetComponent<Health>().IsDead)
        {
            print(gameObject.name + " Should Chase");
           
          
        }
        else
        {
            GetComponent<Mover>().Cancel();
            GetComponent<Fighter>().Cancel();
        }

    }

    private float DistanceToPlayer()
    {
        GameObject player = GameObject.FindGameObjectWithTag("Player");
        GetComponent<Fighter>().CanAttack(player);
        GetComponent<Fighter>().Attack(player);
        return Vector3.Distance(transform.position, player.transform.position);
       
    }
}

}

Privacy & Terms