Unity: Creating player boundaries
Since, we’ve got the player movement set up now we need to make it so that the player can’t go off so we need to make some boundaries. So, write your pseudo code and we will start by setting the boundaries on the Y axis and we’ll be doing that with an if statement. The first if statement we will be writing is to keep the player going higher than they should be so, we will want to stop them once they reach that high point. In pseudo code that be like writing if they reach that high point we make Y axis equal to that point while keeping the X axis at the same point. Then we will do the same for the bottom of the screen. In code that should look something like this:
Next we will do the same for the X axis except for my game I will be making it so that the player warps when it get to a certain point on the left or right.
To do this effect we structure the if statements the same way but we need to figure out what point we need the cube to teleport from and to. To do that just go in your scene view and move the cube to the point you want and use the X position. Once you’ve gotten that and written your code for it your code should look something like this: