Increment Int Once on OnTriggerEnter
I added this code to proceed to the next level in my 2D Platformer
void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.tag == "Doorway")
{
Invoke("NextLevel", 0.1f);
}
}
void NextLevel()
{
transform.position = respawnPoints[levelNumber++].position;
levelNumber++;
}
But for some reason, the int levelNumber is adding way too much. Is there anyone who can help me with this problem?
Comment
Do you realize you are incrementing levelNumber
twice? First here respawnPoints[levelNumber++]
and then the line below?
Oh! Caught that mistake :) But once I put just levelnumber in it,
void NextLevel()
{
levelNumber++;
transform.position = respawnPoints[levelNumber].position;
}
it still adds way too much :(
Are you sure OnTriggerEnter2D
is only called once? Is levelNumber
a simple int or is it declared as static
?