I managed to make my camera scroll when the “up”, “down”, “left” and “right” key is pressed, now I would like to set a limit for the maximum unit that the camera can scroll in the scene, how do I go about doing it, can anyone kindly help me?
void OnGUI ()
{
if ( Input.GetKey("up") )
{
Camera.main.transform.Translate( Vector3.up * Time.deltaTime * scrollSpeed, Space.World );
}
if ( Input.GetKey("down") )
{
Camera.main.transform.Translate( Vector3.down * Time.deltaTime * scrollSpeed, Space.World );
}
if ( Input.GetKey("right") )
{
Camera.main.transform.Translate( Vector3.right * Time.deltaTime * scrollSpeed, Space.World );
}
if ( Input.GetKey("left") )
{
Camera.main.transform.Translate( Vector3.left * Time.deltaTime * scrollSpeed, Space.World );
}
}