I am attempting to make a chess game and I have a manager game object with a script.
I have set up a script for each piece and created a “Check” bool in each one for if that individual piece has put the king into check.
I want a “Check” Bool in my manager script to be true if any of the other scripts “Check” bool is true and false if none of them are.
Putting
“If (check == true)
{
manager.check = true;
}
else
{
manager.check = false;
}”
into each piece script does not produce consistent results and I do understand why but I cannot figure out how to get this right.
Why don’t you keep the bool value for each chess piece in a list, instead of have a script for each chess piece?
It would be better to just manage your chess pieces in your manager class.
List<ChessPiece> chessPieces = new List<ChessPiece>();
// instantiate your pieces and add them to the list or load them from the scene if they exist.
Your chess piece class doesn’t need to be a monobehaviour, but it could contain data like
the Vector3 position, bool check etc