Hi, I browsed the forum a lot to get a clear answer but somehow I ended up tossing onto a wall. I check for an orb and platform collide which enters a trigger and scores up or down. The scoring is working fine but I want the orb to be disappeared after 1 second. I thought I wrote the code but I don’t understand why it is not working. It doesn’t go into the IEnumerator function. I put a breakpoint there to debug it; when I click to step into, it just passes it like it is doing noting too. I created a test function for it and tried to start coroutine again but it still not printing anything and not going into the function when debugging. What am I doing wrong here, what should I do to make the orb disappear after a 1-second pass?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class OrbCatch : MonoBehaviour
{
public GameObject scoreDisplay;
public static int playerScore = 100;
public AudioSource orbCatchFX;
public AudioSource orbCatchSuperFX;
public AudioSource orbCatchWrongFX;
// Start is called before the first frame update
private void OnTriggerEnter(Collider other)
{
System.Console.WriteLine(other.tag);
switch (other.tag)
{
case "GreenCube":
orbCatchFX.Play();
playerScore = playerScore + 10;
scoreDisplay.GetComponent<Text>().text = "Score: " + playerScore;
break;
case "BlueCube":
orbCatchSuperFX.Play();
playerScore = playerScore + 100;
scoreDisplay.GetComponent<Text>().text = "Score: " + playerScore;
break;
case "RedCube":
orbCatchWrongFX.Play();
playerScore = playerScore - 50;
scoreDisplay.GetComponent<Text>().text = "Score: " + playerScore;
break;
default:
break;
}
StartCoroutine(ResetOrb(other.gameObject));
StartCoroutine(myTest());
}
IEnumerator ResetOrb(GameObject orb)
{
yield return new WaitForSeconds(1f);
orb.SetActive(false);
}
IEnumerator myTest()
{
yield return new WaitForSeconds(1f);
print("test");
}
}