Ejemplo n.º 1
0
    private IEnumerator moveToTarget()
    {
        IEnumerable <Vector3> nextPositions = Utility.directions()
                                              .Select(direction => transform.position + direction)
                                              .Where(position => {
            CustomTile tile = maze.getCustomTile(position);
            return(!(tile is ObstacleTile || tile is TrapTile));
        }).Shuffle(rnd);

        Vector3 nextRepairTilePosition = nextPositions.Where(position => {
            RepairTile tile = maze.getTile <RepairTile>(position);
            return(tile != null && tile.repaired);
        }).FirstOrDefault();

        nextRepairTilePosition = nextRepairTilePosition != Vector3.zero ? nextRepairTilePosition : nextPositions.First();

        yield return(StartCoroutine(moveTowards(nextRepairTilePosition)));

        if (checkoutRepairTile())
        {
            yield break;
        }

        yield return(new WaitForSeconds(Random.Range(0f, delay)));

        StartCoroutine(moveToTarget());
    }
Ejemplo n.º 2
0
    private bool checkoutRepairTile()
    {
        RepairTile repairTile = maze.getTile <RepairTile>(transform.position);

        if (repairTile != null)
        {
            if (repairTile.repaired)
            {
                repairTile.interact(gameObject);
                return(true);
            }
        }
        return(false);
    }