【Unity ライブラリ】Input.Touches : 使い方
Rayを使って入力を取得することができるが、"Input.Touches"を使うことで簡単に実装できる。
- Input.Touches(Assetstore)
https://www.assetstore.unity3d.com/en/#!/content/3283
- プロジェクトサンプル
https://dl.dropboxusercontent.com/u/23073684/Blog/InputTouches/WebPlayer/WebPlayer.html
- "InputTouches"使い方
"InputTouches" > "Prefabs" > "InputTouches" をHierarchyに追加する。
以下のスクリプトを保持したゲームオブジェクトを追加する。
using UnityEngine; using System.Collections; public class FlickManager2 : MonoBehaviour { void OnEnable(){ IT_Gesture.onShortTapE += HandleonShortTapE; IT_Gesture.onSwipeEndE += HandleonSwipeEndE; } void OnDisable(){ IT_Gesture.onShortTapE -= HandleonShortTapE; IT_Gesture.onSwipeEndE -= HandleonSwipeEndE; } タップを追加する。 void HandleonShortTapE (Vector2 pos){ } void HandleonSwipeEndE (SwipeInfo sw){ float distance = Vector2.Distance(sw.startPoint, sw.endPoint); if(distance > 50){ if(sw.direction.x > 0){ OnSwipeUp(); } else { OnSwipeDown(); } } } void OnSwipeDown(){ } void OnSwipeUp(){ } }