Currently I am working on 2D Platformer game and there is a bug that gives me headache. Basicly, if our player, collide to an enemy object he dies. on the other hand if he collect a coin, that means he finished the level. According to this situations, the code actives winPanel, or losePanel. But I dont know why, code only works on lose situations, does not active winPanel.
This part is where I check and identify collisions according to the tags.
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Enemy"))
{
GetComponent<TimeControl>().enabled = false;
Die();
}
else if (collision.gameObject.CompareTag("Finish"))
{
Destroy(collision.gameObject);
StartCoroutine(Wait(true));
}
}
Then I am sending true or false to the "Wait" function for enabling win or lose panel.
IEnumerator Wait(bool win)
{
yield return new WaitForSecondsRealtime(2f);
Time.timeScale = 0;
if (win==true)
{
winPanel.SetActive(true);
}
else
{
losePanel.SetActive(true);
}
}
The game is perfectly working on lose or die situations, but not working when player collect coin tagged "Finish".