Hello all,
I’m trying to write code to constrain how far my object can move within a given area. I’m not getting a compiler error but my object also doesn’t stop at the boundary.
void Update ()
{
var transV = Input.GetAxis("Vertical") * playerSpeedV * Time.deltaTime;
var transH = Input.GetAxis("Horizontal") * playerSpeedH * Time.deltaTime;
transform.Translate(transH, transV, 0);
//Player position is equal to 'X' number equals 'X'.
var playerPosition = transform.position;
if (playerPosition.x >= 6)
playerPosition.x = 6;
if (playerPosition.x < -6)
playerPosition.x = -6;
}