Example #1
0
 /*
  * Place a game tile on an unoccupied game square and update the
  * adjacency list of game tiles.
  */
 void PlaceTile(GameSquareBehaviour squareScript)
 {
     newTile.transform.position =
         currSquare.transform.position + Vector3.up;
     adjacencyList[squareScript.IDNum]            = newTile;
     newTile.GetComponent <TileBehaviour>().IDNum =
         squareScript.IDNum;
     squareScript.Occupied = true;
     squaresOccupied++;
     tilePlaced = true;
 }
Example #2
0
    /*
     * Make a new tile.  Get the cursor position in world coordinates
     * and hightlight a game square, if applicable.  Place a game tile on
     * a game square when the user clicks the left mouse button.
     * Need to do all this in fixed update so that collision detection
     * of number squares occurs before scores of tiles are calculated.
     */
    void FixedUpdate()
    {
        // Create a new tile for the appropriate player
        if (makePlayerOneTile)
        {
            MakeNewTile(1);
        }
        else if (makePlayerTwoTile)
        {
            MakeNewTile(2);
        }

        // Get the position of the cursor in world coordinates
        Vector3 cursorPos = mainCamera.ScreenToWorldPoint(new
                                                          Vector3(Input.mousePosition.x, Input.mousePosition.y,
                                                                  mainCamera.farClipPlane));

        cursorPos.y = 10;

        // Check if the cursor is above a game square
        RaycastHit hit;

        if (Physics.Raycast(cursorPos, -Vector3.up, out hit,
                            100.0f, gameSquareLayer))
        {
            prevSquare = currSquare;
            currSquare = hit.transform.gameObject;
            HighlightSquare();
            // When the player clicks the left mouse button, place a game
            // tile on an unoccupied game sqaure.
            if (Input.GetMouseButtonDown(0))
            {
                if (newTile)
                {
                    GameSquareBehaviour squareScript =
                        currSquare.GetComponent <GameSquareBehaviour>();
                    if (!squareScript.Occupied)
                    {
                        PlaceTile(squareScript);
                    }
                }
            }
        }
    }