I'm trying to complete a tutorial video about some piece of code that should prevent players to jump continuosly after they die at some point(when they collide with an obstacle).We assigned gameOver to false at the beginning. Wouldn't !gameOver means true? So Wouldn't this code say that [If we press 'Space' and If the player is on the ground and If the gameOver boolean is true, so when the game ends]
The thing is, I didn't understand the idea of putting an exclamation mark on the boolean that has assigned to 'false' at the start to make it 'false'. Also, the tutor preferred the way of putting an exclamation mark on the boolean's left side (!gameOver). He didn't prefer to write it like this:if (Input.GetKeyDown(KeyCode.Space) && isOnGround && gameOver != true)
The tutor's goal is to prevent players keep jumping after they die. I really couldn't understand how this (!gameOver) works. His code:
public bool gameOver = false;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && isOnGround && !gameOver)
{
playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
isOnGround = false;
playerAnim.SetTrigger("Jump_trig");
}
}
!gameOvermeans completely the same asgameOver == falseorgameOver != true.