Hello! so I am creating a 2D platformer, So I made a spike that kills the player. And Then I made another object that helps the player and then I made a winning flag thats supposed to start the next level but I havent made that so its supposed to say in console “YOU WIN!” but for some reason collider.name isnt working and is detecting the winning flag as a spike. And I cant figure out why.
Heres my code for it (this is in my character controller)
private void OnTriggerEnter2D(Collider2D collider) {
if (collider.name == "jump_pad") {
Vector3 temp = PlayerStartPos.transform.position;
temp.y = transform.position.y + 2;
transform.position = temp;
if (collider.name == "jump_pad_high") {
Vector3 temmie = PlayerStartPos.transform.position;
temmie.y = transform.position.y + 5;
transform.position = temmie;
}
if(collider.name == "winning_flag") {
Debug.Log("YOU WIN!!!!");
}
} else {
RestartLevel();
}
}
private void RestartLevel()
{
Debug.Log("Restarting level");
Vector3 temp = PlayerStartPos.transform.position;
temp.x = PlayerStartPos.transform.position.x;
temp.y = PlayerStartPos.transform.position.y;
temp.z = PlayerStartPos.transform.position.z;
transform.position = temp;
}
Its detecting the winning flag but it thinks its a spike even though I added a if statement that says if its a winning flag. The Winning Flag has a BoxCollider2D with IsTrigger on and has a RigidBody2D with the gravity scale set to 0. Sorry if the answer is extremely obvious I’m new to Unity