基本的に、再生可能な領域を長方形として扱います。次に、そのカメラを占めるその長方形内に小さな矩形を作成します。orthographic size.水平境界を計算するときにカメラのaspect ratioを含めることを忘れないでください。
Rect myArea; // this stores the bounds of your playable area
Camera cam; // this is your orthographic camera, probably Camera.main
GameObject playerObject; // this is your player
float newX = Mathf.Clamp(
playerObject.transform.position.x,
myArea.xMin + cam.orthographicSize * cam.aspect,
myArea.xMax - cam.orthographicSize * cam.aspect
);
float newY = Mathf.Clamp(
playerObject.transform.position.y,
myArea.yMin + cam.orthographicSize,
myArea.yMax - cam.orthographicSize
);
cam.transform.position = new Vector3(newX,newY,cam.transform.position.z);
あなたが(代わりにXYの発言XZ)代替プレーンを使用している場合は、単にすべての計算に対応する寸法をスワップアウト。