Example #1
0
 private void isEnemyInRange()
 {
     if (gameObject.name == "Crossbowman" || gameObject.name == "Crossbowman(Clone)")
     {
         arrowShoot = gameObject.GetComponentInChildren <arrowShoot>();
         if (!arrowShoot.shooting && !moving && !isTurning && !movingAttack)
         {
             GameObject closestTarget = GetClosestEnemy(mouseClick.enemies);
             float      distance      = Vector3.Distance(closestTarget.transform.position, gameObject.transform.position);
             if (distance <= arrowShoot.range)
             {
                 arrow = StartCoroutine(arrowShoot.arrowAttack(closestTarget));
             }
         }
     }
     else if (gameObject.name == "Swordsman" || gameObject.name == "Swordsman(Clone)" || gameObject.name == "Pikeman" || gameObject.name == "Pikeman(Clone)" || gameObject.name == "Axemen" || gameObject.name == "Axemen(Clone)")
     {
         meleeAttack = gameObject.GetComponent <meleeAttack>();
         if (!meleeAttack.isAttacking && !isTurning && !moving && !movingAttack)
         {
             GameObject closestTarget = GetClosestEnemy(mouseClick.enemies);
             float      distance      = Vector3.Distance(closestTarget.transform.position, gameObject.transform.position);
             if (distance <= 20f)
             {
                 meleeDealDamage = StartCoroutine(meleeAttack.attack(closestTarget));
             }
         }
     }
 }
Example #2
0
    protected override void Attack()
    {
        base.Attack();

        if (attack_.attack(50, 400))
        {
            base.Attack();
            speak(QDialog.Status.ATTACK); //Attack talk
        }

        //Attack Logic here
    }
Example #3
0
    public void findAction()
    {
        Vector3 mousePoint = mouseClick.mouseMousePoint();

        hitObject = mouseClick.isObjectSelected();

        if (mousePoint != null)
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                // if (hitobject.tag == "Enemy") {
                // movePoint.add(hitobject);
                // } else {
                // movePoint.Add(mousePoint);
                // }
                movePoint.Add(mousePoint);
            }
            else
            {
                movePoint.Clear();
                // if (hitobject.tag == "Enemy") {
                // movePoint.add(hitobject);
                // } else {
                // movePoint.Add(mousePoint);
                // }
                movePoint.Add(mousePoint);
            }
            if (mouseClick.moveAttack)
            {
                // Checking to see if anything in moveAttack list is true
                for (int i = 0; i < moveAttack.Count; i++)
                {
                    if (moveAttack[i] == true)
                    {
                        // If True add the number it is on to setTrue list
                        setTrue.Add(true);
                    }
                    else
                    {
                        setTrue.Add(false);
                    }
                }
                // Clear the moveAttack List so we can remake it
                moveAttack.Clear();
                for (int i = 0; i < setTrue.Count; i++)
                {
                    if (setTrue[i] != true)
                    {
                        moveAttack.Add(false);
                    }
                    else
                    {
                        moveAttack.Add(true);
                    }
                }
                while (moveAttack.Count != movePoint.Count)
                {
                    moveAttack.Add(false);
                }
                moveAttack.Add(mouseClick.moveAttack);
                mouseClick.moveAttack = false;
            }

            if (hitObject.tag == "Enemy")
            {
                //|| gameObject.name == "Bowman" || gameObject.name == "Bowman(Clone)"
                if (gameObject.name == "Crossbowman" || gameObject.name == "Crossbowman(Clone)")
                {
                    arrowShoot = GetComponentInChildren <arrowShoot>();
                    closeCoroutines();
                    arrow = StartCoroutine(arrowShoot.arrowAttack(hitObject));
                }
                else if (gameObject.name == "Swordsman" || gameObject.name == "Swordsman(Clone)" || gameObject.name == "Pikeman" || gameObject.name == "Pikeman(Clone)" || gameObject.name == "Axemen" || gameObject.name == "Axemen(Clone)")
                {
                    meleeAttack = GetComponent <meleeAttack>();
                    closeCoroutines();
                    meleeDealDamage = StartCoroutine(meleeAttack.attack(hitObject));
                }
            }
            else
            {
                closeCoroutines();
                moveCoroutine = StartCoroutine(moveOverSpeed(gameObject, movePoint, speed));
            }
        }
    }
Example #4
0
 public IEnumerator attackWhileMoving(Vector3 movePoint)
 {
     movingAttack = true;
     while (gameObject.transform.position != movePoint)
     {
         Debug.Log("Not at MovePoint Yet");
         if (gameObject.tag == "unit" && mouseClick.enemies.Count > 0)
         {
             if (gameObject.name == "Crossbowman" || gameObject.name == "Crossbowman(Clone)")
             {
                 arrowShoot = gameObject.GetComponentInChildren <arrowShoot>();
                 if (!arrowShoot.shooting)
                 {
                     Debug.Log("Not Shooting");
                     GameObject closestTarget = GetClosestEnemy(mouseClick.enemies);
                     float      distance      = Vector3.Distance(closestTarget.transform.position, gameObject.transform.position);
                     if (distance <= arrowShoot.range && !isTurning)
                     {
                         Debug.Log("Enemy is Close enough to attack! And I have Finished Turning");
                         arrow = StartCoroutine(arrowShoot.arrowAttack(closestTarget));
                     }
                     else
                     {
                         if (!isTurning)
                         {
                             rotateCoroutine = StartCoroutine(turnTowards(gameObject, movePoint));
                         }
                         gameObject.transform.position = Vector3.MoveTowards(gameObject.transform.position, movePoint, speed * Time.deltaTime);
                     }
                 }
                 yield return(new WaitForEndOfFrame());
             }
             else if (gameObject.name == "Swordsman" || gameObject.name == "Swordsman(Clone)" || gameObject.name == "Pikeman" || gameObject.name == "Pikeman(Clone)" || gameObject.name == "Axemen" || gameObject.name == "Axemen(Clone)")
             {
                 meleeAttack = gameObject.GetComponent <meleeAttack>();
                 if (!meleeAttack.isAttacking)
                 {
                     GameObject closestTarget = GetClosestEnemy(mouseClick.enemies);
                     float      distance      = Vector3.Distance(closestTarget.transform.position, gameObject.transform.position);
                     if (distance <= 20f && !isTurning)
                     {
                         meleeDealDamage = StartCoroutine(meleeAttack.attack(closestTarget));
                     }
                     else
                     {
                         if (!isTurning)
                         {
                             rotateCoroutine = StartCoroutine(turnTowards(gameObject, movePoint));
                         }
                         gameObject.transform.position = Vector3.MoveTowards(gameObject.transform.position, movePoint, speed * Time.deltaTime);
                     }
                 }
                 yield return(new WaitForEndOfFrame());
             }
             else
             {
                 Debug.Log("WTF, How can you not be a unit type?");
                 gameObject.transform.position = Vector3.MoveTowards(gameObject.transform.position, movePoint, speed * Time.deltaTime);
                 yield return(new WaitForEndOfFrame());
             }
         }
         else
         {
             if (!isTurning)
             {
                 rotateCoroutine = StartCoroutine(turnTowards(gameObject, movePoint));
             }
             Debug.Log("There is no units on the map???? Game Should Probably End");
             gameObject.transform.position = Vector3.MoveTowards(gameObject.transform.position, movePoint, speed * Time.deltaTime);
             yield return(new WaitForEndOfFrame());
         }
     }
     mouseClick.moveAttack = false;
     movingAttack          = false;
 }