public static TransparentWall createGameObject(GameObject parent, int r, int c) { GameObject g = Instantiate(Resources.Load("TransparentWall")) as GameObject; g.transform.SetParent(parent.transform); TransparentWall transparentTile = g.GetComponent <TransparentWall>(); transparentTile.init(r, c); return(transparentTile); }
private void FixedUpdate() { //Calculate the Vector direction Vector3 direction = player.transform.position - transform.position; //Calculate the length float length = Vector3.Distance(player.transform.position, transform.position); //Draw the ray in the debug Debug.DrawRay(transform.position, direction * length, Color.white); //The first object hit reference RaycastHit currentHit; //Cast the ray and report the firt object hit filtering by "Wall" layer mask if (Physics.Raycast(transform.position, direction, out currentHit, length, LayerMask.GetMask("Wall"))) { //Getting the script to change transparency of the hit object TransparentWall transparentWall = currentHit.transform.GetComponent <TransparentWall>(); //If the object is not null if (transparentWall) { //If there is a previous wall hit and it's different from this one if (currentTransparentWall && currentTransparentWall.gameObject != transparentWall.gameObject) { //Restore its transparency setting it not transparent currentTransparentWall.ChangeTransparency(false); } //Change the object transparency in transparent. transparentWall.ChangeTransparency(true); currentTransparentWall = transparentWall; } } else { //If nothing is hit and there is a previous object hit if (currentTransparentWall) { //Restore its transparency setting it not transparent currentTransparentWall.ChangeTransparency(false); } } }
// Initializes the Grid public void init(Level level) { // level contains the level data base.init(level); // Passes the level to the game controller to begin the game List <Dictionary <string, object> > levelBoard = level.getBoard(); // Contains information for each game tile if (levelBoard != null) // If there is game data, generate tiles corresponding to the data; Otherwise tiles are randomly generated { for (int i = 0; i < levelBoard.Count; i++) // For every tile in level data { Dictionary <string, object> tileData = levelBoard[i]; // Pull out tile data int c = (int)tileData["x"]; // Pull columns out of tile data int r = (int)tileData["y"]; // Pull rows out string val = (string)tileData["val"]; // pull val out if (String.IsNullOrEmpty(val)) // if the tile has no data, do nothing { } else if (val == "%" || val == "Ice") // if tile is ice, { iceTiles[r][c] = Ice.createGameObject(iceGrid, r, c); // create ice tile on grid at tile coordinates } else if (val == "#" || val == "TransparentWall") // if tile is transparent wall, { tiles[r][c] = TransparentWall.createGameObject(this.gameObject, r, c); // insert transparent wall on grid. } else if (val == "=" || val == "Wall") // if tile is wall, { tiles[r][c] = Wall.createGameObject(this.gameObject, r, c); // insert wall on grid. } else if (val == "*" || val == "Anchor") // if tile is anchor { tiles[r][c] = Anchor.createGameObject(this.gameObject, r, c); // insert anchor on grid. } else if (val == "&" || val == "RootedTile") // if tile is rooted, { tiles[r][c] = RootedTile.createGameObject(this.gameObject, r, c); // insert rooted tile on grid } else if (val[0] >= 'a' && val[0] <= 'z') // if the tile is an alphabet letter, { int bonus = 0; // will contain bonus multiplier if (tileData.ContainsKey("bonus")) // if level data contains a bonus, { bonus = (int)tileData["bonus"]; // store bonus data } tiles[r][c] = WordTile.createGameObject(this.gameObject, r, c, val, bonus); // insert bonus at row and column location on grid if (tileData.ContainsKey("crown")) // if level data contains crown special objects { ((WordTile)tiles[r][c]).setCrown(true); // insert crown in game grid } } } } for (int r = 0; r < row; r++) { for (int c = 0; c < col; c++) { // for every grid tile, if (tiles[r][c] == null) // if the tile has no data, { tiles[r][c] = WordTile.createGameObject(this.gameObject, r, c); // generate a game tile piece with random properties } } } for (int r = 0; r < row; r++) { for (int c = 0; c < col; c++) { // for every grid tile, Tile tile = getTile(r, c); // pull the tile data if (tile.isMovable() || level.isTutorial) // if tile can be moved or the level is a tutorial, { TileBackground tb = (Instantiate(Resources.Load("TileBackground")) as GameObject).GetComponent <TileBackground>(); // create a tile background object; non-movable tiles do not get backgrounds tb.transform.SetParent(gridBackground.transform); // attach the background object to the tile tb.init(r, c); // begin rendering the background object } } } updateMoveUI(); // update the number of moves left in the level updateBoardSize(); // change the board size? Function is not implemented updateText(); // update all words that are connected updateScore(); // update the user score gameController.user.logger(new Dictionary <string, object> { { "d1", "levelStart" }, { "d2", level.level } }); // create a log for debugging purposes }
private void Start() { transparentWall = GameObject.Find(transparentObject).GetComponent <TransparentWall>(); }