title: Enemy movement to only follow player when in range using navmesh
body: <p>I am very new at C# (around 1 week in), so I have been following a lot of tutorials. I am at the moment trying to edit a piece of code (unity tutorial) to only have the enemy follow the player when in a certain range of the player  (10 foot), but unfortunately without changing the code completely, I cannot find a solution. At the moment the enemy will only follow the player when the player is alive (which i also want). </p>
  
  <p>I've tried googling what I want, but I don't want to change the code from what is it too much. I am very new at c# and and currently learning bit by bit, other methods I have found require me changing the code a lot. As far as I understand, the main focus of the code below is for the enemy to be completely controlled by the Nav Mesh Agent, is it possible for me to keep the same technique? </p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  
  public class EnemyMovement : MonoBehaviour
  {
      Transform player;
      PlayerHealth playerHealth;
      EnemyHealth enemyHealth;
      UnityEngine.AI.NavMeshAgent nav;
  
      void Awake()
      {
          // references
          player = GameObject.FindGameObjectWithTag("Player").transform;
          playerHealth = player.GetComponent&lt;PlayerHealth&gt;();
          enemyHealth = GetComponent&lt;EnemyHealth&gt;();
          nav = GetComponent&lt;UnityEngine.AI.NavMeshAgent&gt;();
      }
  
  
      void Update()
      {
          if (enemyHealth.currentHealth &gt; 0 &amp;&amp; playerHealth.currentHealth &gt; 0)
          {
              nav.SetDestination(player.position);
              transform.LookAt(player);
          }
          else
          {
              nav.enabled = false;
          }
      }
  }
  </code></pre>
  
  <p>If possible, I would like to add 2 if functions. 1 being the check if the player is alive, and the other to check if the player is within distance. I don't know much about raycast at the moment, so will this be the next step for me to learn to get this to work how i want?</p>
  
  <p>Thankyou for your time.
  Dean.</p>