I have an issue with my Unity 5 game. When I click on the Pause button, my character jumps before the game is paused.
My script detects the click to trigger the jump jump before the pause button. I tried adding a tag check but that didn't work:
void Update () {
if (Input.GetKeyDown (KeyCode.Space) && Time.timeScale == 1 || Input.GetMouseButtonDown (0) && Time.timeScale == 1 && gameObject.tag != "Pause") {
GetComponent<Rigidbody2D> ().AddForce (Vector2.up * force);
}
You can see in this gif, when I click on the pause button it jumps and pauses directly.
How can I click on the Pause button without making my player jump?
this.gameObject
, ie. your bird. It does not refer to the tags on the object that has been clicked. Also, watch out for doing GetComponent<> every frame. It's usually better to do that once in Start, and then cache the reference in a member variable to use later. \$\endgroup\$