言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

Touch.phase

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public var phase: TouchPhase;
public TouchPhase phase;
public phase as TouchPhase

Description

タッチの状態を取得します

最新のフレームで指が行った行動をタッチ情報として取得します。デバイスによって "ライフタイム"にわたってトラッキングされるのでその間のタッチの開始と終了及び動きはタッチが発生した時から報告されます。 phase プロパティは "switch" 文を使用することにより、より洗練されたハンドリングシステムになります。

var startPos: Vector2;
var direction: Vector2;
var directionChosen: boolean;


function Update () {
	// Track a single touch as a direction control.
	if (Input.touchCount > 0) {
		var touch = Input.GetTouch(0);
		
		// Handle finger movements based on touch phase.
		switch (touch.phase) {
			// Record initial touch position.
			case TouchPhase.Began:
				startPos = touch.position;
				directionChosen = false;
				break;
			
			// Determine direction by comparing the current touch
			// position with the initial one.
			case TouchPhase.Moved:
				direction = touch.position - startPos;
				break;
			
			// Report that a direction has been chosen when the finger is lifted.
			case TouchPhase.Ended:
				directionChosen = true;
				break;
		}
	}
	
	if (directionChosen) {
		// Something that uses the chosen direction...
	}
}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public Vector2 startPos;
    public Vector2 direction;
    public bool directionChosen;
    void Update() {
        if (Input.touchCount > 0) {
            Touch touch = Input.GetTouch(0);
touch.phaseTouchPhase.Began            startPos = touch.position;
            directionChosen = false;
TouchPhase.Moved            direction = touch.position - startPos;
TouchPhase.Ended            directionChosen = true;
        }
        if (directionChosen) {
        }
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public startPos as Vector2

	public direction as Vector2

	public directionChosen as bool

	def Update() as void:
		if Input.touchCount > 0:
			touch as Touch = Input.GetTouch(0)
			UnityScript.Macros.Switch touch.phase:
				case TouchPhase.Began:
					startPos = touch.position
					directionChosen = false
					break 
				case TouchPhase.Moved:
					direction = (touch.position - startPos)
					break 
				case TouchPhase.Ended:
					directionChosen = true
					break 
		if directionChosen:
			pass