I’m having a problem where in the Update of one script, I set the transform of an object, then set a variable in another script to true.
movingPiece.transform.position = temp;
NewTurn ();
BoardSetup.updateBoard = true;
Then, in the BoardSetup script, in Update, it tells each space of the board that it needs to update.
void Update () {
if (GameControlScript.endOfTurn || updateBoard) {
UpdateBoard();
updateBoard = false;
}
}
void UpdateBoard() {
foreach (GameObject boardSpace in boardSpaces) {
BoardSpaceScript spaceScript = boardSpace.GetComponent<BoardSpaceScript>();
spaceScript.needToUpdate = true;
}
}
Finally, in the BoardSpaceScript, in LateUpdate, it checks if there’s something above it.
void CheckOccupier() {
RaycastHit hit;
if(Physics.Raycast(transform.position, Vector3.up, out hit, 3f)){
occupier = hit.transform.gameObject;
isOccupied = true;
BoardPieceScript pieceScript = occupier.GetComponent<BoardPieceScript>();
if (occupier.tag == "Piece")
BoardSetup.gameBoard[xPos,yPos] = pieceScript.pieceID;
} else {
isOccupied = false;
occupier = null;
BoardSetup.gameBoard[xPos,yPos] = 0f;
}
}
However, it won’t detect the object if it’s transform wasn’t above it in that frame. Shouldn’t it already have moved over it by the time LateUpdate is called?