Version: 2020.2
public TouchPhase phase ;

描述

描述触摸阶段。

触摸 phase 指手指在最近的帧更新时采取的操作。因为设备在整个“生命周期”中对触摸进行跟踪,所以触摸的开始和结束以及之间的移动可以在发生触摸的帧上报告。phase 属性可以用作“switch”语句的基础或用作更复杂的状态处理系统的一部分。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Vector2 startPos; public Vector2 direction; public bool directionChosen; void Update() { // Track a single touch as a direction control. if (Input.touchCount > 0) { Touch 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... } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961