Hello unityAnswers community, I’m facing a problem with a code I made in my game: The game is about a rolling ball (basically like the MarbleBlast serie by GarageGames), that works exactly the same as that but with new things I will add. After months of programming (I’m still a C# beginner), I got up to the part where I have to program an appearing (by triggers) and disappearing after 5 seconds (with WaitForSeconds) script. The problem is that I don’t know how to make this work. Following are some snippets of my code and what I tried:
The first thing I tried was this:
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "TTrigger1")
{
Text1.text = "Trigger 1 is working properly";
Debug.Log("Trigger1Activated");
FiveSec();
Text1.text = "";
Debug.Log("Trigger1Deactivated");
}
IEnumerator FiveSec() {
yield return new WaitForSeconds(5);
}
}
But this doesn’t work because if there’s FiveSec() in the trigger script, the code ignores it and goes straight to making Text1 blank (Verified with Debug.Log)
I also tried putting the trigger code in the IEnumerator code, leaving only FiveSec() there.
Also I can’t write the WaitForSeconds code because it has to be in an IEnumerator function. How do I correctly call WaitForSeconds in a void function? Thanks in advance