My monsters froze on the place playing the running animation.
I think that the randomly spawned monsters know to attack the walls but IDK why they don’t move, anyone can take a look at my script
Maybe someone knows how to put the closest in the destination = gameObject in the update function
// Keeping up-to-date where player is, so enemy will follow him
void Update ()
{
//GetComponent<NavMeshAgent> ().destination = GameObject.FindGameObjectsWithTag("wall") = closest;
// On hit by player weapons
if (currentHealth <= 0)
{
//transform.Translate = new Vector3 (0, 0, 0);
//GetComponent<NavMeshAgent> = transform.position;
GetComponent<Animation>().Play("drop down");
Destroy(gameObject,0.5f);
guiDisplay.gold ++;
}
}
// Find the name of the closest wall
GameObject FindClosestWall()
{
GameObject[] find; // Creates an array find
find = GameObject.FindGameObjectsWithTag ("wall"); // Find objects with a tag wall
GameObject closest = null;
float distance = Mathf.Infinity;
Vector3 position = transform.position;
foreach (GameObject go in find)
{
Vector3 diff = go.transform.position - position;
float curDistance = diff.sqrMagnitude;
if (curDistance < distance)
{
closest = go;
distance = curDistance;
}
}
return closest;
}