private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == TagForDestroy && !collision.attachedRigidbody.isKinematic) { Ball ballForDestroy = collision.GetComponent <Ball>(); if (ballForDestroy && ballForDestroy.WasJoin) { Balls.EmitEffect("BallCollision", ballForDestroy.Pos, -ballForDestroy.Vel); baseBall = ballForDestroy.GetBaseBall(); if (baseBall) { Balls.EmitEffect("GameOverCollision", ballForDestroy.Pos, -ballForDestroy.Vel); //Balls.WasGameOver = true; UIManager.GameOver.Show(); } else { float splashSpeed = ballForDestroy.Vel.y * 10f; Splash(ballForDestroy.Pos.x, Mathf.Max(splashSpeed, 0.2f)); Vector3 force = new Vector3(0f, -ballForDestroy.Vel.y, -ballForDestroy.Vel.magnitude * 0.1f); Balls.EmitCoin(ballForDestroy); // GameData.Coins++; SoundManager.Play("gemAdded", Random.Range(0.9f, 1.1f), 1f); Balls.EmitEffect("BallCollision", ballForDestroy.Pos, -ballForDestroy.Vel); if (ballForDestroy.BallType == BallType.Lightning) { ballForDestroy.BallType = BallType.Simple; } ballForDestroy.Kill(Balls.main.BallScore, Vector3.zero, 0f); } } } }
private IEnumerator EmitRoutine(float delay) { yield return(new WaitForSeconds(delay)); SetVelocity(MainParticles, ball.Vel); PlaySound("bomb", Random.Range(0.9f, 1.1f), 0f, 1f); Vector2 pos = transform.position = ball.Pos; bool wasExplode = false; ball.Destroy(); float minRadius = Radius; float maxRadius = Radius * 2f; int collidersCount = Physics2D.OverlapCircleNonAlloc(pos, maxRadius, bombHitColliders, LayerMask.GetMask(CollisionMask)); for (int i = 0; i < collidersCount; i++) { Collider2D hit = bombHitColliders[i]; if (hit.attachedRigidbody != null && !hit.attachedRigidbody.isKinematic) { Vector2 direction = hit.attachedRigidbody.position - pos; int count = Physics2D.LinecastNonAlloc(pos, hit.attachedRigidbody.position, bombRayCastHits, LayerMask.GetMask(CollisionMask)); if (count > 0) { RaycastHit2D raycastHit = bombRayCastHits[0]; if (raycastHit.rigidbody != null && raycastHit.rigidbody == hit.attachedRigidbody) { Debug.DrawLine(pos, hit.attachedRigidbody.position, Color.red, 1f); Ball b = hit.GetComponent <Ball>(); if (b && !b.Destroying) { float distance = Vector2.Distance(pos, b.Pos); Vector2 force = direction.normalized * Power; b.BallBody2D.AddForceAtPosition(force, pos, ForceMode2D.Impulse); yield return(null); //if (b.BallType != BallType.Frozen && b.BallType != BallType.Bubble && b.BallType != BallType.Bomb && distance < minRadius) if (distance < minRadius) { if (b.BallType != BallType.Frozen && b.BallType != BallType.Bubble) { b.BallType = BallType.Crashed; } b.Kill(Balls.main.BallScore, force / distance, distance * 0.05f * Time.timeScale); Balls.EmitEffect("BallCollision", raycastHit.point, force / 10f); wasExplode = true; } } } } } } if (wasExplode) { SoundManager.Play("ballsCrack", pos, Random.Range(1.4f, 1.6f), 1f, 0.05f); } Balls.Shake(); }
private IEnumerator FadeInRoutine(Ball ballForDestroy) { line.startWidth = StartWidth; yield return(new WaitForEndOfFrame()); line.endWidth = EndWidth; EndPS.transform.position = ballForDestroy.transform.position; EndPS.gameObject.SetActive(true); ballForDestroy.Kill(Balls.main.BallScore, Vector3.zero, 0.1f); }
private void ProcessJoinWith(Ball ball, Joint2D joint) { if (!HasGravity) { HasGravity = true; } joints.Add(ball, joint); if (ball.reactAfterJoint) { ball.Kill(Balls.main.BallScore, Vel, 0.25f); } }
private void destroyChain(Queue <Ball> chainForDestroy, BallColor ballColor) { int chainLength = chainForDestroy.Count; while (chainForDestroy.Count > 0) { Ball b = chainForDestroy.Dequeue(); b.Kill(0, Vector3.zero, chainForDestroy.Count * 0.05f); } addScore(chainLength * BallScore, ComboNum); if (chainLength > 3) { gun.SetGunBallType(ballColor); } ComboNum++; }
private IEnumerator EmitRoutine(float delay) { yield return(new WaitForSeconds(delay)); SetVelocity(MainParticles, ball.Vel); PlaySound("freezing", Random.Range(0.9f, 1.1f), 0f, 1f); yield return(new WaitForEndOfFrame()); Vector2 pos = transform.position = ball.Pos; ball.Destroy(); int collidersCount = Physics2D.OverlapCircleNonAlloc(pos, Radius, freezeHitColliders, LayerMask.GetMask(CollisionMask)); for (int i = 0; i < collidersCount; i++) { Collider2D hit = freezeHitColliders[i]; if (hit.attachedRigidbody != null && !hit.attachedRigidbody.isKinematic) { Vector2 direction = hit.attachedRigidbody.position - pos; int count = Physics2D.LinecastNonAlloc(pos, hit.attachedRigidbody.position, freezeRayCastHit, LayerMask.GetMask(CollisionMask)); if (count > 0) { RaycastHit2D raycastHit = freezeRayCastHit[0]; if (raycastHit.rigidbody != null && raycastHit.rigidbody == hit.attachedRigidbody) { Debug.DrawLine(pos, hit.attachedRigidbody.position, Color.red, 1f); Ball b = hit.GetComponent <Ball>(); if (b && !b.Destroying) { Vector2 force = direction.normalized * Power; b.BallBody2D.AddForceAtPosition(force, pos, ForceMode2D.Impulse); if (b.BallType == BallType.Bubble) { b.Kill(Balls.main.BallScore, force, 0f); } else { b.BallType = BallType.Frozen; } yield return(null); } } } } } yield return(null); }
private void OnCollisionEnter2D(Collision2D col) { if (killAfterJoint) { Kill(Balls.main.BallScore, Vel, 0f); return; } if (col.transform.tag == "wall") { if (Vel.sqrMagnitude > 10f) { Balls.EmitEffect("BallCollision", col.contacts[0].point, Vel / 2f); float volume = Mathf.Clamp(Vel.sqrMagnitude / 100f, 0.2f, 1f); float pich = Random.Range(1.25f, 1.5f); PlaySound("wallCollision", pich, volume); } WasJoin = true; } else if (col.transform.tag == tag && !gunBall) { Ball ball = col.gameObject.GetComponent <Ball>(); if (ball) { if (BallType == BallType.Hammer)// ball.BallType == BallType.Hammer) { if (ball.BallType == BallType.Simple) { ball.BallType = BallType.Crashed; } Vector2 force = Vel; ball.BallBody2D.AddForceAtPosition(force, Pos, ForceMode2D.Impulse); ball.Kill(Balls.main.BallScore, force, 0.01f); return; } if (Join(ball)) { } } } }