In my last post I covered how I got our little cube moving, and move it does. If you noticed in the GIF that was posted, our cube was leaving the bounds of the screen. We don’t want that so let’s fix that!

First and lastly, we want to restrict the cube from going out of bounds on the y-axis, so to do that we want to Clamp the cubes transform position between a minimum and maximum value.

Communicate with your player to get them comfortable!

Mathf Documentation: https://docs.unity3d.com/ScriptReference/Mathf.html

Mathf.Clamp Documentation: https://docs.unity3d.com/ScriptReference/Mathf.Clamp.html