I use Unity 5 and I have an issue with my game, when I click on the Pause button my character jumps before the game is paused. My script detects the click for jump before the pause button so for that I add gameObject.tag but doesn'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);
}
Look 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\$ – DMGregory♦ Sep 28 '15 at 4:21