title: Unity: Random NavMesh Agent speed C#?
body: <p>I have Enemy prefab that has navmesh agent. The enemy is controlled by the down give script , how can i have random navmesh agent speed using the give script</p>
  
  <p><strong>Enemy Movement</strong></p>
  
  <pre><code>public class EnemyMovement : MonoBehaviour
  {
      Transform player;               // Reference to the player's position.
      PlayerHealth playerHealth;      // Reference to the player's health.
      EnemyHealth enemyHealth;        // Reference to this enemy's health.
      UnityEngine.AI.NavMeshAgent nav;
  
      void Awake ()
      {
          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 the enemy and the player have health left...
          if(enemyHealth.currentHealth &gt; 0 &amp;&amp; playerHealth.currentHealth &gt; 0)
          {
              // ... set the destination of the nav mesh agent to the player.
              nav.SetDestination (player.position);
          }
          // Otherwise...
          else
          {
              // ... disable the nav mesh agent.
              nav.enabled = false;
          }
      }
  }
  </code></pre>