I Need help with AI,I need help in AI

So i want to make Granny-Styled AI and the chase system don’t work (if object with layer “Player” is in view range then chase) and if player is in view range then it’s still going to the walkpoint
Here is code
using System.Collections;
using UnityEngine;
using UnityEngine.AI;
using Granny4FM.Main;

    namespace Granny4FM.AI
    {
        public class GrannyAI : MonoBehaviour
        {
            public float ViewRange = 10;
            public float AttackRange = 2;
            public float hHalfFov = 45; // Horizontal Half-Field of View (Degrees)
            public int destPoint = 0;
            public Transform[] points;
            public NavMeshAgent granny;
            public Transform player;
            public float walkPointRange = 50f;
            public LayerMask whatIsPlayer;
            public bool isPlayerInView;
            public bool isPlayerInAttackRange;
            private void Start() {
                granny = GetComponent<NavMeshAgent>();
                player = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
                if(granny == null)
                    Debug.LogError("Failed load a Granny AI Controller");
                if(player == null)
                    Debug.LogError("Failed to load player script");
                
                granny.autoBraking = false;
                GotoNextPoint();
            }
            void GotoNextPoint() {
                // Returns if no points have been set up
                if (points.Length == 0)
                    return;
    
                // Set the agent to go to the currently selected destination.
                granny.destination = points[destPoint].position;
    
                // Choose the next point in the array as the destination,
                // cycling to the start if necessary.
                destPoint = (destPoint + 1) % points.Length;
            }
    
            private void Update() {
                var hits = Physics.OverlapSphere(transform.position, ViewRange);
                var hits2 = Physics.OverlapSphere(transform.position, AttackRange);
                foreach (var hit in hits) {
                    if ( hit.gameObject == this.gameObject ) continue; // don't hit self
    
                    // Check FOV
                    var direction = (transform.position - hit.transform.position);
                    var hDirn = Vector3.ProjectOnPlane(direction, transform.up).normalized; // Project onto transform-relative XY plane to check hFov
    
                    var hOffset = Vector3.Dot(hDirn, transform.forward) * Mathf.Rad2Deg; // Calculate horizontal angular offset in Degrees
    
                    if (hOffset > hHalfFov) continue; // Outside of FOV
    
                    Debug.DrawLine(transform.position, hit.transform.position, Color.yellow);
    
                    if (hit.transform.gameObject.layer == whatIsPlayer) {
                        isPlayerInView = true;
                        print("hitplr");
                    }
                }
                foreach (var hit in hits2) {
                    if ( hit.gameObject == this.gameObject ) continue; // don't hit self
    
                    // Check FOV
                    var direction = (transform.position - hit.transform.position);
                    var hDirn = Vector3.ProjectOnPlane(direction, transform.up).normalized; // Project onto transform-relative XY plane to check hFov
    
                    var hOffset = Vector3.Dot(hDirn, transform.forward) * Mathf.Rad2Deg; // Calculate horizontal angular offset in Degrees
    
                    if (hOffset > hHalfFov) continue; // Outside of FOV
    
                    Debug.DrawLine(transform.position, hit.transform.position, Color.red);
    
                    if (hit.transform.gameObject.layer == whatIsPlayer) {
                        print("hitplr2");
                        isPlayerInAttackRange = true;
                    }
                }
    
                if(!isPlayerInView && !isPlayerInAttackRange) Patrolling();
                if(isPlayerInView && !isPlayerInAttackRange) Chasing();
                if(isPlayerInView && isPlayerInAttackRange) Attacking();
            }
            private void Patrolling(){
    
                isPlayerInView = false;
                isPlayerInAttackRange = false;
                if (!granny.pathPending && granny.remainingDistance < 0.5f)
                    GotoNextPoint();
            }
            private void Chasing(){
                granny.destination = player.position;
                if(granny.remainingDistance == 10f){
                    Patrolling();
                }
            }
            private void Attacking(){
                Debug.Log("Attacked");
            }
            /*private Vector3 GenerateWalkPoint(){
                float randomX = Random.Range(-walkPointRange, walkPointRange);
                float randomY = Random.Range(-walkPointRange, walkPointRange);
                float randomZ = Random.Range(-walkPointRange, walkPointRange);
                Vector3 point = new Vector3(transform.position.x + randomX, transform.position.y + randomY, transform.position.z + randomZ);
                return point;
            }*/
        }
    }

,I want to make Granny-Style AI and the chase system (if player is in range then chase)
and if player is in view then enemy is still going to the point
Here is code

    using System.Collections;
    using UnityEngine;
    using UnityEngine.AI;
    using Granny4FM.Main;
    
    namespace Granny4FM.AI
    {
        public class GrannyAI : MonoBehaviour
        {
            public float ViewRange = 10;
            public float AttackRange = 2;
            public float hHalfFov = 45; // Horizontal Half-Field of View (Degrees)
            public int destPoint = 0;
            public Transform[] points;
            public NavMeshAgent granny;
            public Transform player;
            public float walkPointRange = 50f;
            public LayerMask whatIsPlayer;
            public bool isPlayerInView;
            public bool isPlayerInAttackRange;
            private void Start() {
                granny = GetComponent<NavMeshAgent>();
                player = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
                if(granny == null)
                    Debug.LogError("Failed load a Granny AI Controller");
                if(player == null)
                    Debug.LogError("Failed to load player script");
                
                granny.autoBraking = false;
                GotoNextPoint();
            }
            void GotoNextPoint() {
                // Returns if no points have been set up
                if (points.Length == 0)
                    return;
    
                // Set the agent to go to the currently selected destination.
                granny.destination = points[destPoint].position;
    
                // Choose the next point in the array as the destination,
                // cycling to the start if necessary.
                destPoint = (destPoint + 1) % points.Length;
            }
    
            private void Update() {
                var hits = Physics.OverlapSphere(transform.position, ViewRange);
                var hits2 = Physics.OverlapSphere(transform.position, AttackRange);
                foreach (var hit in hits) {
                    if ( hit.gameObject == this.gameObject ) continue; // don't hit self
    
                    // Check FOV
                    var direction = (transform.position - hit.transform.position);
                    var hDirn = Vector3.ProjectOnPlane(direction, transform.up).normalized; // Project onto transform-relative XY plane to check hFov
    
                    var hOffset = Vector3.Dot(hDirn, transform.forward) * Mathf.Rad2Deg; // Calculate horizontal angular offset in Degrees
    
                    if (hOffset > hHalfFov) continue; // Outside of FOV
    
                    Debug.DrawLine(transform.position, hit.transform.position, Color.yellow);
    
                    if (hit.transform.gameObject.layer == whatIsPlayer) {
                        isPlayerInView = true;
                        print("hitplr");
                    }
                }
                foreach (var hit in hits2) {
                    if ( hit.gameObject == this.gameObject ) continue; // don't hit self
    
                    // Check FOV
                    var direction = (transform.position - hit.transform.position);
                    var hDirn = Vector3.ProjectOnPlane(direction, transform.up).normalized; // Project onto transform-relative XY plane to check hFov
    
                    var hOffset = Vector3.Dot(hDirn, transform.forward) * Mathf.Rad2Deg; // Calculate horizontal angular offset in Degrees
    
                    if (hOffset > hHalfFov) continue; // Outside of FOV
    
                    Debug.DrawLine(transform.position, hit.transform.position, Color.red);
    
                    if (hit.transform.gameObject.layer == whatIsPlayer) {
                        print("hitplr2");
                        isPlayerInAttackRange = true;
                    }
                }
    
                if(!isPlayerInView && !isPlayerInAttackRange) Patrolling();
                if(isPlayerInView && !isPlayerInAttackRange) Chasing();
                if(isPlayerInView && isPlayerInAttackRange) Attacking();
            }
            private void Patrolling(){
    
                isPlayerInView = false;
                isPlayerInAttackRange = false;
                if (!granny.pathPending && granny.remainingDistance < 0.5f)
                    GotoNextPoint();
            }
            private void Chasing(){
                granny.destination = player.position;
                if(granny.remainingDistance == 10f){
                    Patrolling();
                }
            }
            private void Attacking(){
                Debug.Log("Attacked");
            }
            /*private Vector3 GenerateWalkPoint(){
                float randomX = Random.Range(-walkPointRange, walkPointRange);
                float randomY = Random.Range(-walkPointRange, walkPointRange);
                float randomZ = Random.Range(-walkPointRange, walkPointRange);
                Vector3 point = new Vector3(transform.position.x + randomX, transform.position.y + randomY, transform.position.z + randomZ);
                return point;
            }*/
        }
    }

It looks like the problem with your AI is that it is not properly changing its behavior when the player is in its view or attack range. Instead, it just continues to move to its walk points even if it can see or attack the player.

To fix this, you will need to add some logic to your Update() function that checks whether the player is in view or attack range, and if so, changes the AI’s behavior accordingly. For example, you could add an if statement that checks if isPlayerInView is true, and if so, makes the AI chase the player instead of continuing to move to its walk points. Similarly, you could add another if statement that checks if isPlayerInAttackRange is true, and if so, makes the AI attack the player instead of chasing or moving to walk points.