Beispiel #1
0
    // PLAYER
    public IEnumerator attackEnemy(EnemyAttributes enemy, bool player)
    {
        EnemyAttributes playerEnemy       = gameManager.getPlayerBehavior().transform.GetComponent <EnemyAttributes>();
        Vector3         hitGroundPosition = gameManager.getPlayerBehavior().getHitGround();

        //Debug.Log("start attacking");
        if (!playerEnemy.getIsAttackingEnemy() && enemy != this)
        {
            playerEnemy.setIsAttackigEnemy(true);
            playerEnemy.lookAtTargetEnemy(enemy);

            while (playerEnemy.getIsAttackingEnemy())
            {
                if (hitGroundPosition != gameManager.getPlayerBehavior().getHitGround())
                {
                    //Debug.Log("not attacking anymore because player clicked elsewhere");
                    enemy.setMobIndicator(false);
                    enemy.setHealthbar(false);
                    enemy.setAllIndicatorsFallsAndActivate("red");
                    break;
                }
                if (enemy == null)
                {
                    break;
                }
                else
                {
                    enemy.setHealthbar(true);
                    enemy.setMobIndicator(true);
                    enemy.setAllIndicatorsFallsAndActivate("yellow");
                    //Debug.Log("attacking enemy running");
                }

                if (!playerEnemy.getAttackCooldown())
                {
                    playerEnemy.dealDamage(enemy);
                }
                yield return(null);
            }
            //Debug.Log("end attacking");
            playerEnemy.setIsAttackigEnemy(false);
        }
    }
Beispiel #2
0
    // THIS ONE IS FOR PLAYER
    public IEnumerator walkToEnemy(EnemyAttributes enemy)
    {
        bool            walkingToEnemy    = true;
        EnemyAttributes player            = this;
        Vector3         hitGroundPosition = gameManager.getPlayerBehavior().getHitGround();


        while (walkingToEnemy)
        {
            enemy.setMobIndicator(true);
            enemy.setAllIndicatorsFallsAndActivate("yellow");
            //Debug.Log("player WALKINMG to enemy");

            if (hitGroundPosition != gameManager.getPlayerBehavior().getHitGround())
            {
                //Debug.Log("new walking position");
                enemy.setMobIndicator(false);
                enemy.setAllIndicatorsFallsAndActivate("red");
                break;
            }

            if (Vector3.Distance(gameManager.getPlayerBehavior().getPlayerPosition(), enemy.getPosition()) < player.getAttackRange())
            {
                //Debug.Log("clsoe enough");
                stopMovement();
                player.setCurrentTarget(enemy);
                StartCoroutine(attackEnemy(enemy, true));

                break;
            }
            else
            {
                player.getNavMeshAgent().SetDestination(enemy.getPosition());
            }
            yield return(null);
        }
    }