2016-09-29 3 views
0

화면을 두드 리거나 화면을 스 와이프하는 것을 결정하려고합니다. 왼쪽, 오른쪽, 위, 아래에서 스 와이프를 결정하고 싶습니다. 지금 왼쪽 또는 오른쪽으로 스 와이프하면 내 플레이어도 바뀝니다. 어떤 일이 일어날 지 모른다. 그것은 하나 또는 다른 것이어야하며, 왼쪽이나 오른쪽으로 돌리거나 움직여야합니다. 제 질문은 어떻게 5 가지를 모두 결정할 수 있습니까? 화면을 두드리는 것만으로 왼쪽, 오른쪽, 위, 아래로 스 와이프합니다. 는 여기에 내가 검색의 조금이 코드를 발견 내 코드스 와이프 또는 탭 확인

using UnityEngine; 
using System.Collections; 
public class PlayerMotor : MonoBehaviour { 

    private CharacterController controller; 
    private Vector3 moveVector; 
    private float speed = 2.0f; 
    private float verticalVelocity = 0.0f; 
    private float gravity = 12.0f; 

    public Touch touch; 

    private void Start() { 

     controller = GetComponent<CharacterController>(); 
    } 
    private void Update() 
    {   
     moveVector = Vector3.zero; 
     if (controller.isGrounded) 
     { 
      verticalVelocity = -0.5f; 
     } 
     else 
     { 
      verticalVelocity -= gravity * Time.deltaTime; 
     } 
     if (Input.GetMouseButton (0)) 
     { 
      if (touch.position.x == touch.deltaPosition.x && touch.position.x == touch.deltaPosition.x) 
      { //3px accuracy, stationery :P 
       moveVector.x = transform.forward.x * speed; 
       transform.Rotate (new Vector3 (0, -90, 0)); 
      } 
      else if (touch.position.x != touch.deltaPosition.x && touch.position.x != touch.deltaPosition.x) 
      { 
       if (Input.mousePosition.x > Screen.width/2) 
        moveVector.x = speed; 
       else 
        moveVector.x = -speed; 
      } 
     } 
     moveVector.y = verticalVelocity; 
     moveVector.z = transform.forward.z * speed; 
     controller.Move (moveVector * Time.deltaTime); 
    } 
} 

답변

0

입니다. (Here)

모든 if (currentSwipe...) 문이 클릭을 감지하는 작업을해야 후 else 문을 추가

//inside class 
Vector2 firstPressPos; 
Vector2 secondPressPos; 
Vector2 currentSwipe; 

public void Swipe() 
{ 
    if(Input.touches.Length > 0) 
    { 
     Touch t = Input.GetTouch(0); 

     if(t.phase == TouchPhase.Began) 
     { 
       //save began touch 2d point 
      firstPressPos = new Vector2(t.position.x,t.position.y); 
     } 

     if(t.phase == TouchPhase.Ended) 
     { 
       //save ended touch 2d point 
      secondPressPos = new Vector2(t.position.x,t.position.y); 

       //create vector from the two points 
      currentSwipe = new Vector3(secondPressPos.x - firstPressPos.x, secondPressPos.y - firstPressPos.y); 

      //normalize the 2d vector 
      currentSwipe.Normalize(); 

      //swipe upwards 
      if(currentSwipe.y > 0 currentSwipe.x > -0.5f currentSwipe.x < 0.5f) 
      { 
       Debug.Log("up swipe"); 
      } 

      //swipe down 
      if(currentSwipe.y < 0 currentSwipe.x > -0.5f currentSwipe.x < 0.5f) 
      { 
       Debug.Log("down swipe"); 
      } 

      //swipe left 
      if(currentSwipe.x < 0 currentSwipe.y > -0.5f currentSwipe.y < 0.5f) 
      { 
       Debug.Log("left swipe"); 
      } 

      //swipe right 
      if(currentSwipe.x > 0 currentSwipe.y > -0.5f currentSwipe.y < 0.5f) 
      { 
       Debug.Log("right swipe"); 
      } 
     } 
    } 
} 
+0

하는 경우는 (currentSwipe.y> 0 currentSwipe.x> -0.5f currentSwipe.x <0.5F) Be : if (currentSwipe.y> 0 && currentSwipe.x> -0.5f && currentSwipe.x <0.5f)? 그렇지 않으면 ')' – Lynnstrum

+0

이 클래스는 PointerClick에서 사용해야하고 주위를 스 와이프하고 다음을 클릭해야합니까? – GuardFromUA

관련 문제