Beispiel #1
0
 // Update is called once per frame
 void Update()
 {
     if (enemy.isAlive())
     {
         if (!reloading)
         {
             enemy.GetTarget();
             if (enemy.returnTarget() != null)
             {
                 if (enemy.inTargetDist())                        //not walking, in range
                 {
                     rb.velocity = new Vector2(0, 0);
                     enemy.rotateToTarget(enemy.returnTargetPosition(), transform.position);
                     enemy.inCombat = true;
                     idleImg.SetActive(false);
                     fireImg.SetActive(true);
                     Attack();
                 }
                 else
                 {
                     Walk();
                     enemy.rotateToTarget(enemy.returnTargetPosition(), transform.position);
                     enemy.inCombat = false;
                     idleImg.SetActive(true);
                     fireImg.SetActive(false);
                 }
                 if (enemy.inCombat && enemy.returnTarget() != null)
                 {
                     Attack();
                 }
                 else
                 {
                     enemy.setElapsedTime(0);
                 }
             }
             else                     //if no targets
             {
                 enemy.inCombat = false;
                 idleImg.SetActive(true);
                 fireImg.SetActive(false);
                 Walk();
                 enemy.rotateToTarget(new Quaternion(0, 0, 0, 1), transform.rotation);
             }
         }
         else                 //if you are reloading
         {
             enemy.inCombat = false;
             idleImg.SetActive(true);
             fireImg.SetActive(false);
             Retreat();
         }
     }
     else             //if not alive
     {
         rb.velocity = new Vector2(0, 0);
     }
 }