Mathf.Clamp

Al Heck
May 13, 2021

Let’s limit the movement of our ship bounds vs using an if statement.

That’s a lot of code that says we can’t go past 6 or -4 on our screen. Let’s use mathf.clamp to keep the player within these two bounds.

This code does exactly what was done up above without all of the if statements.

--

--

Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ