Exemplo n.º 1
0
    public GameObject PlaceTile(int x, int y, int tileID)
    {
        if (x < 0 || x > _gridSize)
        {
            Debug.LogError(string.Format("GameObject: {0}\nScript: LevelManager\nError: X coordinate is out of bound.", gameObject.name));
            return(null);
        }

        if (y < 0 || y > _gridSize)
        {
            Debug.LogError(string.Format("GameObject: {0}\nScript: LevelManager\nError: Y coordinate is out of bound.", gameObject.name));
            return(null);
        }

        if (tileID < 0 || tileID > _tile.Length)
        {
            Debug.LogError(string.Format("GameObject: {0}\nScript: LevelManager\nError: tile id is out of bound.", gameObject.name));
            return(null);
        }

        GameObject newTile = Instantiate(_tile[tileID]);

        newTile.transform.parent   = _startPosition.transform;
        newTile.transform.position = new Vector3(_startPosition.transform.position.x + (TileSize() * x), _startPosition.transform.position.y - (TileSize() * y));
        newTile.name = string.Format("Tile {0}x{1}", x, y);
        Tube newTube = newTile.GetComponent <Tube>();

        if (newTube != null)
        {
            newTube.SetManager(this);
            newTube.SetCoordinates((byte)x, (byte)y);
        }
        _grid[x, y] = newTile;
        return(newTile);
    }