1234567891011121314151617181920212223242526272829303132333435363738 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- public class LongPressDetector : MonoBehaviour
- {
- private bool isPressing = false;
- private float pressDuration = 0f;
- //public AdMobManager adMobManager;
- private void Update(){
- if (Input.GetMouseButtonDown(0) || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)){
- isPressing = true;
- pressDuration = 0f;
- }
- else if (Input.GetMouseButton(0) || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Stationary))
- {
- if (isPressing){
- if(Input.GetMouseButton(0)){
- pressDuration += Time.deltaTime;
- }else{
- pressDuration += Input.GetTouch(0).deltaTime;
- }
- if(pressDuration >= 1.5f && Main.Global.deleytime>=5f){
- // 长按超过3秒的操作
- Debug.Log("觸發長按");
- //adMobManager.HideBanner();
- pressDuration = 0f;
- Main.Global.長案=true;
- Main.Global.deleytime=0f;
- }
- }
- }else if (Input.GetMouseButtonUp(0) || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended)){
- Main.Global.deleytime=0f;
- isPressing = false;
- pressDuration = 0f;
- }
- }
- }
|