I forget Unity all. Human is amazing.

How to get tap in Unity is the following,

// Update is called once per frame
void Update () {
	if (Input.touchCount > 0) {
		Touch myTouch = Input.GetTouch (0);					// get first tap
		// Touch[] myTouches = Input.touches;				// if you get multi tap
		// for(int i = 0; i < Input.touchCount; i++){}		// process in for loop

		// process for tap
		Vector2 vec2 = myTouch.position;
		Debug.Log("(" + vec2.x + ", " + vec2.y + ")" );

		// start, move, and finish of tap
		if(myTouch.phase == TouchPhase.Began)
		{
			// start tap
		}
		else if (myTouch.phase == TouchPhase.Moved)
		{
			// move tap
		}
		else if (myTouch.phase == TouchPhase.Ended)
		{
			// finish tap
		}
	}

}

Add the above script to any object.

 

References:

https://unity3d.com/jp/learn/tutorials/topics/mobile-touch/multi-touch-input?playlist=45798

https://docs.unity3d.com/ScriptReference/Touch.html?_ga=2.133886541.23970780.1495464928-455626883.1490587154

Categories: memo

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

備忘録。半年くらいUnity触ってなかったら全部忘れてた。人ってすごいね。

Unityでタップを取得する場合は下記。

// Update is called once per frame
void Update () {
	if (Input.touchCount > 0) {
		Touch myTouch = Input.GetTouch (0);					// 一つ目のタップ
		// Touch[] myTouches = Input.touches;				// 複数のタップを取得したい場合はこちら
		// for(int i = 0; i < Input.touchCount; i++){}		// ループで回して処理する。

		// タップしている間の処理
		Vector2 vec2 = myTouch.position;
		Debug.Log("(" + vec2.x + ", " + vec2.y + ")" );

		// タップの開始、移動、終了時の処理
		if(myTouch.phase == TouchPhase.Began)
		{
			// タップの開始
		}
		else if (myTouch.phase == TouchPhase.Moved)
		{
			// タップの移動
		}
		else if (myTouch.phase == TouchPhase.Ended)
		{
			// タップの終了
		}
	}

}

空のオブジェクトでも作ってスクリプトを割り当てればテストできる。

 

参考:

https://unity3d.com/jp/learn/tutorials/topics/mobile-touch/multi-touch-input?playlist=45798

https://docs.unity3d.com/ScriptReference/Touch.html?_ga=2.133886541.23970780.1495464928-455626883.1490587154

Categories: memo

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.