void Clamp() { // 画面左下のワールド座標をビューポートから取得 Vector2 min = Camera.main.ViewportToWorldPoint(new Vector2(0, 0)); // 画面右上のワールド座標をビューポートから取得 Vector2 max = Camera.main.ViewportToWorldPoint(new Vector2(1, 1)); Vector2 pos = transform.position; pos.x = Mathf.Clamp(pos.x, min.x, max.x); pos.y = Mathf.Clamp(pos.y, min.y, max.y); transform.position = pos; }