Inheritance: MonoBehaviour
示例#1
0
    /* loads selected puzzle, places player on puzzle */
    private void loadPuzzle(int puzzle_id)
    {
        currentPuzzle = (GameObject)Instantiate (Resources.Load ("tetris_puzzles/TilePuzzle_"+puzzle_id));
        all_tiles = GameObject.FindObjectsOfType<TetrisTile>();

        /* find our start & end tiles */
        foreach (TetrisTile a_tile in all_tiles)
        {
            if(a_tile.name == "tile_end")
                endTile = a_tile;
            else if(a_tile.name == "tile_start")
                startTile = a_tile;
        }

        /* put the player on the puzzle */
        resetPlayer ();
    }
示例#2
0
    /* update puzzle state*/
    void Update()
    {
        if (!puzzleActive)
            return;

        /* if the player falls off the puzzle, reset him */
        if (player.transform.position.y < startTile.transform.position.y - 20)
            resetPlayer ();

        TetrisTile currentTile = getCurrentTile();

        /* if landed on a new tile ... */
        if (currentTile && currentTile != lastTile)
        {

            /* rotate all tiles */
            foreach(TetrisTile a_tile in all_tiles)
                a_tile.startRotation();

            /* don't rotate the tile we landed on, or the one we jumed from */
            lastTile.freezeTile();
            currentTile.freezeTile();

            /* reached the end of the puzzle, destroy and head back to game */
            if(currentTile.name == "tile_end")
            {
                /* do other shit here if we need to */

                destroyPuzzle();
                return;
            }

            /* save current tile as the new last tile */
            lastTile = currentTile;
        }
    }
示例#3
0
 /* reset player location ontop of the start tile */
 void resetPlayer()
 {
     player.transform.position = new Vector3 (startTile.transform.position.x, startTile.transform.position.y + 2f, startTile.transform.position.z);
     lastTile = getCurrentTile ();
 }