0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

マルチタップの方法について

Last updated at Posted at 2016-12-06

マルチタップについて手こずったのでメモします。

やり方

指の数が増えるごとに指を反応してくれるようにした。
このままスクリプトを入れて設定すれば大丈夫です。

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Touch : MonoBehaviour {

	public Text text;
	public int touchCount;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		// CountUpメソッドを呼び出す
		CountUp ();
	}

	//タップしたら数が増える
	public void CountUp(){
		//デバッグ用のクリック操作
		if (Input.GetMouseButtonDown (0)) {
			touchCount++;
			text.text = touchCount.ToString();
		}

		if( 0 < Input.touchCount){
			// タッチされている指の数だけ処理
			for(int i = 0; i < Input.touchCount; i++){
				// タッチ情報をコピー
				UnityEngine.Touch t = Input.GetTouch(i);
				// タッチしたときかどうか
				if(t.phase == TouchPhase.Began ){
					// タップされた時の処理
					touchCount++;
					text.text = touchCount.ToString();
				}
			}
		}
	}
}
0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?