// I have 'CheckNotes' triggered every time a note is collected.
void CheckNotes ()
{
if (notes == 0)
{
starText.text = "0%";
}
if (notes == 1)
{
starText.text = "33%";
}
if (notes == 2)
{
starText.text = "66%";
}
if (notes == 3)
{
starText.text = "100%";
winText.text = "Level Complete!";
SceneManager.LoadScene("Level2")
}
Everything works, but as soon as the third note is collected it immediately loads the next scene/level. If I remove āSceneManager.LoadScene(āLevel2ā)ā it displayes 100% and āLevel Completedā. I was wondering if there was a way to display āLevel Completedā and then a couple seconds later load the next scene. So the player has time to see āLevel Completedā before the scene changes. I am new to Unity, any help is appreciated, I havenāt been able to find a working answer on any other posts. Thanks. (C#)
You would Invoke an event to run after x seconds, something like this:
using UnityEngine;
using UnityEngine.SceneManagement;
public class MyClass : MonoBehaviour {
// Time in seconds to delay (five seconds for example):
public float delayTime = 5f;
int notes = 0;
void OnTriggerEnter2D(Collider2D other){
if(notes == 3){
Invoke("DelayedAction", delayTime);
}
}
void DelayedAction(){
SceneManager.LoadScene("Level2");
}
}
Please donāt necro-post for a simple runtime error.
The complete error message contains everything you need to know to fix the error yourself.
The important parts of the error message are:
the description of the error itself (google this; you are NEVER the first one!)
the file it occurred in (critical!)
the line number and character position (the two numbers in parentheses)
also possibly useful is the stack trace (all the lines of text in the lower console window)
Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.
Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?
All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you donāt have to stop your progress and fiddle around with the forum.
Remember: NOBODY here memorizes error codes. Thatās not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.
If you just need a general ādo something later please,ā I always use this pattern: