private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Surface")) { if (!winCondition) { OnTouchSurface?.Invoke(transform.position.x); OnUnderWater?.Invoke(false); canMove = false; } else { print("WIN"); OnWinning?.Invoke(); saveManagerScript.SaveFieldsIntoStatistic(); SceneManager.LoadScene("GameWinScene"); } } if (collision.CompareTag("Seaweed")) { OnCollisionWeed?.Invoke(); StartCoroutine(TouchSeaweedRoutine()); } if (collision.CompareTag("Pearl")) { OnPickUpPearl?.Invoke(); } if (collision.CompareTag("GigaPearl")) { OnPickUpGigaPearl?.Invoke(); winCondition = true; } if (collision.CompareTag("SpeedBuff")) { OnPickUpSpeedBuff?.Invoke(); StartCoroutine(PickUpSpeedBuff()); } if (collision.CompareTag("OxygenBuff")) { OnPickUpOxygenBuff?.Invoke(); } }
IEnumerator DepleteAir() { while (rectTransform.offsetMax.x > airBarSize) { if (isUnderwater) { rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x - airDepletionAmount, rectTransform.offsetMax.y); } yield return(new WaitForSeconds(airDepletionSpeed)); } OnOxygenDepletion?.Invoke(); saveManagerScript.SaveFieldsIntoStatistic(); SceneManager.LoadScene("GameEndScene"); StopCoroutine(DepleteAir()); }