작은 문제를 해결할 수있는 누군가가 있기를 바랍니다.마우스가 화면 밖에있을 때 움직임을 멈추는 방법
현재 입력 도구가 주 카메라에 연결되어있어 사용자가 마우스를 창 가장자리로 이동하여지도 주위를 화면 이동시킬 수 있지만 수정하려고 시도한 약간의 문제가 발생했습니다. 나 자신을 아무 소용이 없습니다.
마우스가 창 밖으로 나가면 여전히 패닝이 발생하여 디버깅 중이거나 다른 응용 프로그램을 사용할 때 불안감을 느낍니다. 그래서 누군가가 마우스가 게임 창 바깥에있을 때 움직임을 막을 수 있기를 바랍니다.
다음은 입력 관리자 코드입니다.
using UnityEngine;
using System.Collections;
public class InputManager : MonoBehaviour {
public Vector3 position = new Vector3(0,0, -10);
public int boundary = 50;
public int speed = 4;
private int screenBoundsWidth;
private int screenBoundsHeight;
// Use this for initialization
void Start()
{
screenBoundsWidth = Screen.width;
screenBoundsHeight = Screen.height;
}
// Update is called once per frame
void Update()
{
if (Input.mousePosition.x > screenBoundsWidth - boundary) {
position.x += speed * Time.deltaTime;
}
if (Input.mousePosition.x < 0 + boundary) {
position.x -= speed * Time.deltaTime;
}
if (Input.mousePosition.y > screenBoundsHeight - 10) {
position.y += speed * Time.deltaTime;
}
if (Input.mousePosition.y < 0 + boundary) {
position.y -= speed * Time.deltaTime;
}
Camera.mainCamera.transform.position = position;
}
}
감사합니다.
편집
나는 주위에 해키 작업과 함께 온,하지만 여전히 윈도우의 외부 주변의 특정 위치에서 발생하는 움직임을 발생합니다. 나는 누군가가 더 나은 해결책을 찾길 바란다.
if (Input.mousePosition.x < screenBoundsWidth && Input.mousePosition.y < screenBoundsHeight) {
if (Input.mousePosition.x > screenBoundsWidth - boundary) {
position.x += speed * Time.deltaTime;
}
}
if (Input.mousePosition.x > 0 && Input.mousePosition.y > 0) {
if (Input.mousePosition.x < 0 + boundary) {
position.x -= speed * Time.deltaTime;
}
}
if (Input.mousePosition.y < screenBoundsHeight && Input.mousePosition.x < screenBoundsWidth) {
if (Input.mousePosition.y > screenBoundsHeight - 22) {
position.y += speed * Time.deltaTime;
}
}
if (Input.mousePosition.y > 0 && Input.mousePosition.x > 0) {
if (Input.mousePosition.y < 0 + boundary) {
position.y -= speed * Time.deltaTime;
}
}
이것은 WinForms 용입니까? – user959631
불행하게도 Unity3D 용이지만 C#을 사용하고 있습니다. – Flickayy