﻿using UnityEngine;

[CreateAssetMenu (menuName = "AI/Decisions/TargetReached")]
public class Decision_OnTargetReached : Decision {

	public bool overrideDistanceToReach;
	public float distanceToReach;
	
	public override bool Decide(StateController controller) {
		return isTargetReached(controller);
	}

	private bool isTargetReached(StateController controller) {
		var enemyControl = controller as Enemy_StateController;
		
		enemyControl.navMeshAgent.destination = enemyControl.chaseTarget.position;		

		if(!overrideDistanceToReach)
			distanceToReach = enemyControl.navMeshAgent.stoppingDistance;

		if(enemyControl.navMeshAgent.remainingDistance <= distanceToReach && !enemyControl.navMeshAgent.pathPending) {
			enemyControl.navMeshAgent.isStopped = true;
			return true;
		} else {
			enemyControl.navMeshAgent.isStopped = false;
			return false;
		}
	}
}

﻿using UnityEngine;

[CreateAssetMenu (menuName = "AI/Decisions/TargetReached")]
public class Decision_OnTargetReached : Decision {

	public bool overrideDistanceToReach;
	public float distanceToReach;
	
	public override bool Decide(StateController controller) {
		return isTargetReached(controller);
	}

	private bool isTargetReached(StateController controller) {
		var enemyControl = controller as Enemy_StateController;
		
		enemyControl.navMeshAgent.destination = enemyControl.chaseTarget.position;		

		if(!overrideDistanceToReach)
			distanceToReach = enemyControl.navMeshAgent.stoppingDistance;

		if(enemyControl.navMeshAgent.remainingDistance <= distanceToReach && !enemyControl.navMeshAgent.pathPending) {
			return true;
		} else {
			return false;
		}
	}
}

Remove NavMeshAgent handling from decision script (not its role)
Remove NavMeshAgent handling from decision script (not its role)
