Unity3D에서 3D 모바일 응용 프로그램을 작업하고 있지만 최근에 문제가 발생했습니다. 내 캐릭터를 움직일 수있는 조이스틱이 있습니다. 조이스틱은 GUI 텍스처입니다. 경계선이 설정되어 화면 전체에서 조이스틱을 움직일 수 없습니다. 손가락이 경계 바깥으로 움직이면 조이스틱은 최대한 멀리 움직이며 손가락을 뒤로 움직이면 손가락과 함께 움직입니다. 이것은 훌륭하지만 화면의 오른쪽을 따라 다른 손가락을 움직이면 카메라가 회전하도록 설정할 것입니다. 한 손가락이 조이스틱에 있고 다른 손가락을 화면의 오른쪽에 놓으면 문제가 발생합니다. 화면의 오른쪽을 따라 한 손가락을 움직이면 조이스틱이 재설정됩니다! 이것은 내 코드입니다 ... 제발 도와주세요!Unity3D에서 두 번째 손가락이 gui 조이스틱의 위치를 조작하는 것을 중지하는 방법
#pragma strict
var gui: GUITexture;
var pixelInsetPosResSet: boolean = true;
var playerCharacter: GameObject;
public var leftID: int;
function Start()
{
guiPixelInsetResSet();
gui.color.a=.1;
gui.transform.position.z=1;
}
function JoystickGUIMove()
{
// Detecting Touch
if(Input.touchCount > 0){
for(var i : int = 0; i < Input.touchCount; i++){
var touch : Touch = Input.GetTouch(i);
if(touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position))
{
leftID = Input.GetTouch(i).fingerId;
pixelInsetPosResSet = false;
}
if(pixelInsetPosResSet == false)
{
if(Input.GetTouch(i).fingerId == leftID)
{
// Moving GUI and Character
gui.pixelInset.x = touch.position.x+Screen.width/(-1.78);
gui.pixelInset.y = touch.position.y+Screen.height/(-1.63);
gui.color.a=.5;
if(gui.pixelInset.y > Screen.height/(-3.5))
{
playerCharacter.transform.position.z = playerCharacter.transform.position.z+(8*Time.deltaTime);
}
else if(gui.pixelInset.y > Screen.height/(-2.6))
{
playerCharacter.transform.position.z = playerCharacter.transform.position.z+(2*Time.deltaTime);
}
else if(gui.pixelInset.y < Screen.height*(-.475))
{
playerCharacter.transform.position.z = playerCharacter.transform.position.z-(2*Time.deltaTime);
}
if(gui.pixelInset.x > Screen.width/(-2.4))
{
playerCharacter.transform.position.x = playerCharacter.transform.position.x+(2*Time.deltaTime);
}
if(gui.pixelInset.x > Screen.width/(-2.4) && gui.pixelInset.y > Screen.height/(-3.5))
{
playerCharacter.transform.position.x = playerCharacter.transform.position.x+(5*Time.deltaTime);
}
if(gui.pixelInset.x < Screen.width/(-2.1))
{
playerCharacter.transform.position.x = playerCharacter.transform.position.x-(2*Time.deltaTime);
}
if(gui.pixelInset.x < Screen.width/(-2.1) && gui.pixelInset.y > Screen.height/(-3.5))
{
playerCharacter.transform.position.x = playerCharacter.transform.position.x-(5*Time.deltaTime);
}
//Setting boundaries
if(pixelInsetPosResSet == false)
{
if((touch.position.y+Screen.height/(-1.63)) > Screen.height/(-4.5))
{
gui.pixelInset.y = Screen.height/(-4.5);
}
if((touch.position.y+Screen.height/(-1.63)) < Screen.height*(-.5))
{
gui.pixelInset.y = Screen.height*(-.5);
}
if((touch.position.x+Screen.width/(-1.78)) > Screen.width/(-2.6))
{
gui.pixelInset.x = Screen.width/(-2.6);
}
if((touch.position.x+Screen.width/(-1.78)) < Screen.width*(-.5))
{
gui.pixelInset.x = Screen.width*(-.5);
}
}
else
{
pixelInsetPosResSet = true;
pixelInsetPositionReset();
}
}
}
pixelInsetPositionReset();
}
}
}
function pixelInsetPositionReset()
{
// Reseting Joystick position
for(var i : int = 0; i < Input.touchCount; i++){
var touch : Touch = Input.GetTouch(i);
if(touch.phase == TouchPhase.Ended)
{
pixelInsetPosResSet = true;
guiPixelInsetResSet();
}
}
}
function guiPixelInsetResSet()
{
// Set width and height automatically
if (pixelInsetPosResSet == true)
{
gui.pixelInset.width=Screen.width/8.5;
gui.pixelInset.height=gui.pixelInset.width;
// Set position automatically
gui.pixelInset.x=Screen.width/(-2.25);
gui.pixelInset.y=Screen.height/(-2.35);
}
}
function Update()
{
pixelInsetPositionReset();
gui.color.a=.1;
JoystickGUIMove();
}
고마워요! 나는 이것을 아직 시험 할 수는 없지만 기회가 생기면 곧 갈 것이다! –
확인. 문제가 있는지 물어보십시오. Unity3d의 대화방 http://chat.stackoverflow.com/rooms/37624/unity3d-developers – Nick
아직도 문제가 있습니다 ... 편집 된 질문. 당신이 위대한 것이 도움이 될 수 있다면 :) –