private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Ball" || collision.gameObject.tag == "PoweredBall") { float ballPointX = collision.contacts[0].point.x; float racketPointX = collision.gameObject.transform.position.x; Vector2 collisionPoint = collision.contacts[0].point; float effectPointX = ballPointX - racketPointX; if (signalManager.IsActiveSticky()) { audioSources[4].time = 0.85f; audioSources[4].Play(); } else { audioSources[0].time = 0.2f; audioSources[0].Play(); } } }
void OnCollisionEnter2D(Collision2D collision) { switch (collision.gameObject.tag) { case "Racket": isPrecipitating = false; Draw(); mainManager.ClearComboBonus(); Accelerate(2.0f); rigidbody2D.velocity = Vector2.zero; float theLengthOfRacket = collision.gameObject.GetComponent <Racket>().GetLength(); int indexVelocity = mainManager.GetLevel(); float ballPointX = collision.contacts[0].point.x; float racketPointX = collision.gameObject.transform.position.x; float pointX = ballPointX - racketPointX; float degree = (1.0f - pointX / theLengthOfRacket) * Mathf.PI / 2; Vector2 reflectionVelocity = new Vector2(currentVelocity * Mathf.Cos(degree), currentVelocity * Mathf.Sin(degree)); if (signalManager.IsActiveSticky()) { stickedPointX = pointX; stickedVelocity = reflectionVelocity; isSticked = true; isConstant = false; rigidbody2D.velocity = Vector2.zero; screenNavigationManager.SetSticky(true); } else { isConstant = true; rigidbody2D.velocity = reflectionVelocity; } break; case "FailZone": StopBall(); mainManager.ClearComboBonus(); StartCoroutine(mainManager.Missing()); break; case "PrecipitateBlock": if (isPrecipitating) { ChangeMovingAngle(); } if (!signalManager.IsActiveTrapGuard()) { float collisionPointY = collision.contacts[0].point.y - collision.transform.position.y; if (collisionPointY <= -20.0f) { collision.gameObject.GetComponent <PrecipitateBlock>().StartEffect(); PrecipitateExtremely(); } } break; case "RigidbodyPrecipitate": if (isPrecipitating) { ChangeMovingAngle(); } if (!signalManager.IsActiveTrapGuard()) { float collisionPointX = collision.contacts[0].point.x - collision.transform.position.x; float collisionPointY = collision.contacts[0].point.y - collision.transform.position.y; if (collisionPointY <= -22.0f) { if (collisionPointX <= -10.0f) { collision.gameObject.GetComponent <SKL144SystemPrecipitate>().StartEffectLeft(); } if (collisionPointX >= 10.0f) { collision.gameObject.GetComponent <SKL144SystemPrecipitate>().StartEffectRight(); } PrecipitateExtremely(); } } break; case "Rigidbody": case "BlockSupport": if (isPrecipitating) { ChangeMovingAngle(); } break; case "Protector": isPrecipitating = false; Draw(); mainManager.ClearComboBonus(); Accelerate(5.0f); float degreeProtector = Random.Range(45.0f * Mathf.Deg2Rad, 135.0f * Mathf.Deg2Rad); Vector2 reflectionVelocityProtector = new Vector2(currentVelocity * Mathf.Cos(degreeProtector), currentVelocity * Mathf.Sin(degreeProtector)); rigidbody2D.velocity = reflectionVelocityProtector; isConstant = true; break; } }