Exemplo n.º 1
0
    public IEnumerator enemies()
    {
        if (currentNode.burning || isBurning)
        {
            currentPath = null;
            yield return(new WaitForSeconds(0.25f));
        }

        var theenemies = Physics.OverlapSphere(transform.position, radius, enemy).ToList();

        enemiesInRange = new List <GameObject>();

        foreach (Collider col in theenemies)
        {
            if (col.gameObject.GetComponent <EnemyEntity>() != null)
            {
                enemiesInRange.Add(col.gameObject);
            }
        }

        //move enemies out of range


        foreach (GameObject enemy in map.thisEnemy)
        {
            EnemyEntity entity = enemy.GetComponent <EnemyEntity>();
            if (!enemiesInRange.Contains(enemy))
            {
                entity.moveOutOfRange();
                // if(entity.thoughtBubble.enabled)
                //  entity.RemoveEnemyHud();
            }
        }

        //move enemies in range

        foreach (GameObject enemy in enemiesInRange)
        {
            EnemyEntity entity = enemy.GetComponent <EnemyEntity>();

            if (entity.sleeping == false)
            {
                map.GeneratePathForEnemy(currentNode.x, currentNode.y, enemy);

                entity.MoveNextTile();

                //wait till its done moving/attacking
                if (entity.currentPath != null)
                {
                    if (entity.currentPath.Count == 2)
                    {
                        yield return(new WaitUntil(() => entity.done));
                    }
                }
            }
            else
            {
                entity.awareness += (1 / Vector3.Distance(transform.position, entity.transform.position)) * 25;
                entity.ifBurning();
                entity.stateSprites();
            }
        }


        //check if there are enemies in neighbouring nodes, to set attack button

        displayAttButton();

        //return control

        inControl = true;
    }