Copying and Pasting cs Code
In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.
For example, you can follow the pattern in this listing: void Update () {
#if UNITY_EDITOR
if (Input.GetKeyDown(KeyCode.Z)) {
GameManager.Instance.GameState.Checkmate();
GameOver(p1,GameOverType.CHECKMATE); //TODO delete
} else if (Input.GetKeyDown(KeyCode.X)) {
GameManager.Instance.GameState.Checkmate();
GameOver(p2,GameOverType.CHECKMATE); //TODO delete
} else if (Input.GetKeyDown(KeyCode.C)) {
GameManager.Instance.GameState.Stalemate();
GameOver(p2,GameOverType.STALEMATE);
}
#endif
if (!ready) return;
if (gameState.IsGameOver) return;
//EXPERIMENT_TIMER
if (whiteTurn) {
whiteTimer -= Time.deltaTime;
if (whiteTimer < 0 ) {
whiteTimer = 0;
GameManager.Instance.GameState.OutOfTime();
GameOver(p2, GameOverType.OUT_OF_TIME);
}
UpdateWhiteTimer();
} else {
blackTimer -= Time.deltaTime;
if (blackTimer < 0 ) {
blackTimer = 0;
GameManager.Instance.GameState.OutOfTime();
GameOver(p1, GameOverType.OUT_OF_TIME);
}
UpdateBlackTimer();
}
}
#if UNITY_EDITOR
if (Input.GetKeyDown(KeyCode.Z)) {
GameManager.Instance.GameState.Checkmate();
GameOver(p1,GameOverType.CHECKMATE); //TODO delete
} else if (Input.GetKeyDown(KeyCode.X)) {
GameManager.Instance.GameState.Checkmate();
GameOver(p2,GameOverType.CHECKMATE); //TODO delete
} else if (Input.GetKeyDown(KeyCode.C)) {
GameManager.Instance.GameState.Stalemate();
GameOver(p2,GameOverType.STALEMATE);
}
#endif
if (!ready) return;
if (gameState.IsGameOver) return;
//EXPERIMENT_TIMER
if (whiteTurn) {
whiteTimer -= Time.deltaTime;
if (whiteTimer < 0 ) {
whiteTimer = 0;
GameManager.Instance.GameState.OutOfTime();
GameOver(p2, GameOverType.OUT_OF_TIME);
}
UpdateWhiteTimer();
} else {
blackTimer -= Time.deltaTime;
if (blackTimer < 0 ) {
blackTimer = 0;
GameManager.Instance.GameState.OutOfTime();
GameOver(p1, GameOverType.OUT_OF_TIME);
}
UpdateBlackTimer();
}
}