코드가 작동하지 않습니다. 카메라를 클램프하려고하지만 작동하지 않습니다. 카메라를 고정하는 방법?Unity3D에서 카메라를 클램핑하는 방법
using UnityEngine;
using System.Collections;
public class MoveCamera : MonoBehaviour
{
public float sensitivity = 4.0f;
private Vector3 mouseOrigin;
private bool isRotating;
private float speed = 2.0f;
private float minX = -45.0f;
private float maxX = 45.0f;
private float minY = -10.0f;
private float maxY = 10.0f;
float rotationY = 0.0f;
float rotationX = 0.0f;
void Update()
{
if (Input.GetMouseButtonDown (0)) {
mouseOrigin = Input.mousePosition;
isRotating = true;
}
if (!Input.GetMouseButton (0))
isRotating = false;
if (isRotating) {
Vector3 pos = Camera.main.ScreenToViewportPoint (Input.mousePosition - mouseOrigin);
transform.RotateAround (transform.position, transform.right, -pos.y * sensitivity);
transform.RotateAround (transform.position, Vector3.up, pos.x * sensitivity);
rotationY = Mathf.Clamp (rotationY, minY, maxY);
rotationX = Mathf.Clamp (rotationX, minX, maxX);
transform.localEulerAngles = new Vector3 (-rotationY, rotationX, 0);
}
}
}
그런데 외부 도구를 사용하고 싶지 않습니다. 그런데 "X"대신 "Y"라는 코드를 수정했습니다. 빠른 답장을 보내 주셔서 감사합니다. :) –
제가 언급 한 외부 도구는 실제로 외부입니다. Unity에 전혀 영향을 미치지 않습니다 ... 그리고 제가 게시 한 픽스가 아직 충분하지 않은 경우 코드에서 Debug.Log를 사용하여 원하는 것 대신 실제로 무엇을하는지보십시오. 마찬가지로, Mathf.Clamp는 의도 한대로 작동합니다. 심지어 코드에서도 ... –