Exemplo n.º 1
0
    private void _on_SensingTimer_timeout()
    {
        Enemy[] enemies = gameNode.GetEnemies();

        if (enemies != null)
        {
            float distanceAway = float.MaxValue;
            Enemy newTarget    = null;

            foreach (Enemy enemy in enemies)
            {
                if (enemy != null && !enemy.IsDead())
                {
                    float dist = Position.DistanceSquaredTo(enemy.Position);
                    if (dist < rangeSquared && dist < distanceAway)
                    {
                        dist      = distanceAway;
                        newTarget = enemy;
                    }
                }
            }

            target = newTarget;
        }
    }