Need help on resetting player if he dies on LvL 2

hey again guys! Since you are all so kind to me I’m going to ask here again:

So basically I have a script that resets the position of the player, if the player falls down from a platform.
The script says, if the player falls down from the platform then transform the position of the player to the start area (0,0,0).

Like so: else if(transform.position.y < -4){ reset position }

But I’m having trouble on my second level. Because the second level is in the same scene but is just moved a lot to the right (x axis) on the screen (so you can’t see it from lvl 1).

I thought this script would work, but it just doesn’t. Could you help me out guys?

else if(transform.position.y < -4 && transform.position.x > 100){
    transform.position.y = 0; //set the y axis that the player will spawn to
        transform.position.x = 120; // set the x axis that the player will spawn to
        transform.position.z = 0; // set the z axis that the player will spawn to
        rigidbody.velocity = Vector3.zero;
}

As you can see, I tried to do it like this: if the player is below the platforms AND is 100 units to the right, THEN reset the position to level 2 starting area.

Help please :slight_smile:

Concerning your code:
The else if kinda implies you have an if before it. I’m guessing you are checking whether the player is below y=-4 first, then whether he’s below y=4 and x>100 - the first condition will always be true when the second could be true, so the second one is never evaluated. Change the order.

Still, this way of doing it is not going to scale well. Hardcoding dependencies makes it very difficult to modify you game. It’s much better to have the code adjust such things dynamically instead of writing it out explicitly.
The easiest way would be to give the player a vector3 variable for the position he’s supposed to spawn at. When entering a new level, the script that moves the player there also sets the new spawn point.