Esempio n. 1
0
    void StartNode()
    {
        // Find if there are enemies or not
        if (FindEnemies() > 0)
        {
            selectedEnemy = enemies[0];

            // Are the enemies close enough to attack?
            // If yes:
            if (AttackEnemies() == State.SUCCESS)
            {
                if (!fighting)
                {
                    fighting = true;
                    FightEnemies();
                }
            }
            // If no:
            else
            {
                SeekEnemies();
            }
        }
        else
        {
            FindPath();
        }
    }
Esempio n. 2
0
    IEnumerator FightEnemy()
    {
        if (currentAttackingEnemies.Count > 0)
        {
            EnemyAgentScript currentEnemy = currentAttackingEnemies[0];

            // while current enemy has health
            while (currentEnemy.hitsRemaining > 0)
            {
                currentEnemy.hitsRemaining--;
                yield return(new WaitForSeconds(1.0f));
            }

            currentAttackingEnemies.Remove(currentEnemy);

            // Once all enemies killed
            Debug.Log("all killed");
            behaviourTree.fighting = false;
        }
    }