I'm making the SpaceShooter game in Unity.
Here is the function.
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
Player.GetComponent<Rigidbody>().velocity=movement*speed;
Player.GetComponent<Rigidbody> ().rotation = Quaternion.Euler(0.0f,0.0f,Player.GetComponent<Rigidbody> ().velocity.x * -tilt);
}
In the above code when I add the Clamp function to limit the Ship to the boundaries, the Ship size reduces from the sides. This is the Clamp function code that reduces the size of the ship.
Player.GetComponent<Rigidbody> ().position=new Vector3
(
Mathf.Clamp(Player.GetComponent<Rigidbody>().position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp(Player.GetComponent<Rigidbody>().position.z, boundary.zMin, boundary.zMax)
);
I've given the screen boundary values accurately in the Clamping funtion.