Hey there. I got a problem with my game. I looked on google to solve the problem, but I was not able to do that. So here we go: I have a gameobject with this code:
void OnTriggerEnter2D(Collider2D coll)
{
if(coll.gameObject.tag == "Player")
{
Debug.Log("TriggerEnter");
PlayerController controller = coll.gameObject.GetComponent<PlayerController>();
StartCoroutine(controller.Die());
Destroy(this.gameObject);
}
}
So when a player enters the object is will triger and calls the players’ Die method. After that it will destroy itself.
The players’ die method looks like this:
public static IEnumerator WaitForRealSeconds(float time)
{
float start = Time.realtimeSinceStartup;
while (Time.realtimeSinceStartup < start + time)
{
yield return null;
}
}
public IEnumerator Die()
{
Time.timeScale = 0.0f;
Debug.Log("pause");
yield return StartCoroutine(WaitForRealSeconds(4));
Debug.Log("defaq");
Time.timeScale = 1;
}
The problem is that the game doesn’t resume after 4 seconds. I think this happens since that original caster destorys itself. But I don’t know how to fix this. Thanks in advance!