void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == tagColliderName) { this.GetComponent <Rigidbody2D> ().gravityScale = 0; this.GetComponent <Rigidbody2D> ().velocity = new Vector2(0, this.GetComponent <Rigidbody2D>().velocity.y); if (currentSide == CurrentSide.LEFT) { float xPos = other.transform.position.x; xPos -= .2f; Vector3 newPosition = this.gameObject.transform.position; newPosition.x = xPos; this.gameObject.transform.position = newPosition; } else if (currentSide == CurrentSide.RIGHT) { float xPos = other.transform.position.x; xPos += .2f; Vector3 newPosition = this.gameObject.transform.position; newPosition.x = xPos; this.gameObject.transform.position = newPosition; } } if (other.gameObject.tag == tagColliderName && isJumping) { isJumping = false; isMoving = false; if (currentSide == CurrentSide.LEFT) { currentSide = CurrentSide.RIGHT; } else if (currentSide == CurrentSide.RIGHT) { currentSide = CurrentSide.LEFT; } } if (other.gameObject.tag == "coin") { ScordeHandler.AddCoin(100); Destroy(other.gameObject); audioHandler.InstanceCoinSound(); } if (other.gameObject.tag == "falling_object") { Destroy(this.gameObject); gameManager.SetGameOver(); } if (other.gameObject.tag == "canon_ball") { Destroy(this.gameObject); gameManager.SetGameOver(); } if (other.gameObject.tag == "finish_level") { Destroy(this.gameObject); gameManager.SetSuccess(); } }