Question by 
               HaiHouTV · Oct 13, 2017 at 11:13 AM · 
                script.scripting beginner  
              
 
              I need my AI Unit attack the nearest enemy and It needs to do this until enemies finished.
I'm new at coding actually I started coding 5 day ago. Think two group of swordsman and they need to kill enemy group. I made a script that two units walk to each other, attack and die. I have some issues that sometimes units hit themselves, sometimes hit multiple at one time and more little issues. Any assistance would be appreciated. :')
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.AI;
 using UnityEngine.UI;
 
 public class BadSkeleton : MonoBehaviour {
 
     public Slider healthbar;
 
     public GameObject GoodSkeleton;
 
     static Animator anim;
 
     private NavMeshAgent nav;
 
 
     // Use this for initialization
     void Start () 
     {
         
         nav = GetComponent<NavMeshAgent> ();
         anim = GetComponent<Animator> ();
     }
 
     // Update is called once per frame
     void Update ()
     {
         nav.SetDestination (GoodSkeleton.transform.position);
         {
             anim.SetBool ("isIdle", false);
             if (transform.position.magnitude > 5) {
                 GoodSkeleton.transform.Translate (0, 0, 0.00f);
                 anim.SetBool ("isWalking", true);
                 anim.SetBool ("isAttacking", false);
             } 
             else 
             {
                 anim.SetBool ("isAttacking", true);
                 anim.SetBool ("isWalking", false);
                 {
                     if (healthbar.value <= 0)
                         anim.SetBool ("isDead", true);`
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Set the username with an inputfield ? 3 Answers
1st Person shooter, move player forward where cam is facing 1 Answer
Possible Infinite Loop Freezing Game 1 Answer
Player respawn at death position 0 Answers
Modify a text object using script 1 Answer