private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.layer…
- User
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.layer == LayerMask.NameToLayer("Barrel")) { if (marioDeath != null) { Instantiate(marioDeath, transform.position, transform.rotation, null); } currentHealth--; ResetScene(); } else if (collision.gameObject.layer == LayerMask.NameToLayer("Win")) { SceneManager.LoadScene("_Scene_DonkeyKong25M"); } } make it so that there is 3 seconds before ResetScene() is called
- Assistant
To add a delay of 3 seconds before calling the
ResetScene()method, you can use theCoroutineclass in Unity. Here's an example of how you can modify the code:csharpprivate IEnumerator DelayedResetScene() { yield return new WaitForSeconds(3f); // 3 seconds delay ResetScene(); } private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.layer == LayerMask.NameToLayer("Barrel")) { if (marioDeath != null) { Instantiate(marioDeath, transform.position, transform.rotation, null); } currentHealth--; StartCoroutine(DelayedResetScene()); // Start the delay before calling ResetScene() } else if (collision.gameObject.layer == LayerMask.NameToLayer("Win")) { SceneManager.LoadScene("_Scene_DonkeyKong25M"); } }