1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
/*
 상하좌우스와이프와 그냥 클릭을 구분 가능하게 함
사용할 스크립트에 MonoBehaviour 대신에 TouchGesture를 상속시켜주고
버추얼 함수들을 오버로딩해서 사용하셈
*/
public class TouchGesture : MonoBehaviour
{
    private const float SwipeDis = 10;//스와이프 허용 범위 수정하고 싶으면 이거 수정하셈
    private Vector2 StartPos;
 
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            StartPos = Input.mousePosition;
        }
        if (Input.GetMouseButtonUp(0))
        {
            Vector2 p = (Vector2)Input.mousePosition - StartPos;
 
            if (Mathf.Abs(p.x) < SwipeDis && Mathf.Abs(p.y) < SwipeDis)
                GetClick();
            else
            {
                if (Mathf.Abs(p.x) > Mathf.Abs(p.y))
                    GetSwipe(StartPos, new Vector2(Mathf.Sign(p.x), 0));
                else if (Mathf.Abs(p.x) < Mathf.Abs(p.y))
                    GetSwipe(StartPos, new Vector2(0, Mathf.Sign(p.y)));
            }
        }
    }
 
    public virtual void GetClick() { }
    public virtual void GetSwipe(Vector2 StartPos, Vector2 dir) { }
}
 
cs


'내가 만든거' 카테고리의 다른 글

길따라 로봇 road robot 제작기(BIC 전시기)  (1) 2019.09.25
등산 시뮬레이터  (0) 2018.06.23
맵 에디터 !!!!  (0) 2018.05.11
유니티 사운드 매니저  (2) 2017.08.22
마인크래프트 만들었다  (0) 2017.05.24
블로그 이미지

stuban

ㅇ.ㅇ

,