private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "wall") { ChangeDirection(); } else if (collision.gameObject.tag == "tempWall") { Destroy(collision.gameObject); StartCoroutine(Stun()); } else if (collision.gameObject.tag == "floor" || collision.gameObject.tag == "floorCrusher") { canJump = true; } else if (collision.gameObject.tag == "topCrusher" && _rigidbody.velocity.y <= 0) { _respawner.Respawn(); _scoreManager.SubtractPlayerScore(gameObject.tag); Destroy(gameObject); } if (collision.gameObject.tag == "Player" || collision.gameObject.tag == "Player2") { PlayerScript other = collision.gameObject.GetComponent <PlayerScript>(); if (!isAttacking && other.isAttacking) { if (!isInvincible && !other.isInvincible) { DestroyAndRespawn(); } else if (isInvincible || other.isInvincible) { ChangeDirection(); } } else { ChangeDirection(); speed += 0.05f * (Mathf.Abs(speed) / speed); } Debug.Log(speed); } }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "wall" || collision.gameObject.tag == "tempWall") { ChangeDirection(); if (collision.gameObject.tag == "tempWall") { Destroy(collision.gameObject); } speed += 0.01f * (Mathf.Abs(speed) / speed); Debug.Log(speed); } else if (collision.gameObject.tag == "floor") { canJump = true; } else if (collision.gameObject.tag == "Player" || collision.gameObject.tag == "Player2") { IcePlayerScript other = collision.gameObject.GetComponent <IcePlayerScript>(); if (isAttacking && !other.isAttacking) { _scoreManager.AddPlayerScore(gameObject.tag); _respawner.Respawn(); Destroy(collision.gameObject); } else { ChangeDirection(); } speed += 0.01f * (Mathf.Abs(speed) / speed); Debug.Log(speed); } }