How to Make a Chess Game with Unity | Ray Wenderlich

Not every successful game involves shooting aliens or saving the world. Board games, and chess, in particular, have a history that spans thousands of years. In this tutorial, you’ll build a 3D chess game in Unity.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/186631/how-to-make-a-chess-game-with-unity

@bcbroom
Hello, I’m doing a chess-like game and I based this https://www.raywenderlich.com/186631/how-to-make-a-chess-game-with-unity project as a substructure, but I have a problem here, the rook just want to cancel it going back. Can you write how it’s done? Thank you.

using System.Collections.Generic;
using UnityEngine;

public class Rook : Piece
{
public override List MoveLocations(Vector2Int gridPoint)
{
List locations = new List();

    foreach (Vector2Int dir in RookDirections)
    {
        for (int i = 1; i < 8; i++)
        {
            Vector2Int nextGridPoint = new Vector2Int(gridPoint.x + i * dir.x, gridPoint.y + i * dir.y);
            locations.Add(nextGridPoint);
            if (GameManager.instance.PieceAtGrid(nextGridPoint))
            {
                break;
            }
        }
    }

    return locations;
}

}