- Home /
Why don't my enemies walk toward me?
the enemies use the animation but they don't walk, help
this is the script:
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;
}
}
}
}
atleast i think this is the script that is cousing the problem
put a debug.log in the the if and else statement to see if they are being called
thanks but i am a beginner with unity so i dunno shit.... so how does that work?
Your last comment just nailed it. You "dunno shit" and you are trying to do nav mesh agent movement. Get simpler, move your guy, then move your guy to a target, then move your guy to a selection of target and so on. Leveling up on each state.
Yeah i know but i downloaded à game from THE thingy ..... And those enemy's didn't walk so....that's why
Answer by Michael_-01-_ · Apr 15, 2015 at 11:21 AM
Try to difine the else parameter more, and the nav, try
Else if(enemyHealth.currentHealth > 0 && playerHealth.currentHealth > 0)
{nav.SetPosition(transform.position);