Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

navmesh error

Discussion in 'Scripting' started by SoDifferent, May 4, 2015.

  1. SoDifferent

    SoDifferent

    Joined:
    May 4, 2015
    Posts:
    1
    Hi ! Im new in unity3d and i need some help...How i can solve this?

    if this is
    using UnityEngine;
    using System.Collections;

    namespace CompleteProject
    {
    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.
    NavMeshAgent nav; // Reference to the nav mesh agent.


    void Awake ()
    {
    // Set up the references.
    player = GameObject.FindGameObjectWithTag ("Player").transform;
    playerHealth = player.GetComponent <PlayerHealth> ();
    enemyHealth = GetComponent <EnemyHealth> ();
    nav = GetComponent <NavMeshAgent> ();
    }


    void Update ()
    {
    // If the enemy and the player have health left...
    if(enemyHealth.currentHealth > 0 && playerHealth.currentHealth > 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;
    }
    }
    }
    }
     
  2. relic1882

    relic1882

    Joined:
    Mar 11, 2015
    Posts:
    45