Ejemplo n.º 1
0
        /// <summary>
        /// Creates the game object for the piece -> loads the texture, creates an sprite, assigns the texture and position the game object in world space over the center cell.
        /// </summary>
        void CreatePiece()
        {
            // Creates the piece
            Sprite sprite = Resources.Load <Sprite> ("Sprites/piece");

            piece = new GameObject("Piece");
            SpriteRenderer spriteRenderer = piece.AddComponent <SpriteRenderer> ();

            spriteRenderer.sprite = sprite;

            // Parents the piece to the grid and sets scale
            piece.transform.SetParent(grid.transform, false);
            piece.transform.localScale = Vector3.one * 0.25f;

            // Get central cell of checker board
            Cell centerCell      = grid.CellGetAtPosition(4, 4);
            int  centerCellIndex = grid.CellGetIndex(centerCell);

            grid.MoveTo(piece, centerCellIndex, 0);
        }