説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

LongPressDetector.cs 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class LongPressDetector : MonoBehaviour
  5. {
  6. private bool isPressing = false;
  7. private float pressDuration = 0f;
  8. //public AdMobManager adMobManager;
  9. private void Update(){
  10. if (Input.GetMouseButtonDown(0) || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)){
  11. isPressing = true;
  12. pressDuration = 0f;
  13. }
  14. else if (Input.GetMouseButton(0) || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Stationary))
  15. {
  16. if (isPressing){
  17. if(Input.GetMouseButton(0)){
  18. pressDuration += Time.deltaTime;
  19. }else{
  20. pressDuration += Input.GetTouch(0).deltaTime;
  21. }
  22. if(pressDuration >= 1.5f && Main.Global.deleytime>=5f){
  23. // 长按超过3秒的操作
  24. Debug.Log("觸發長按");
  25. //adMobManager.HideBanner();
  26. pressDuration = 0f;
  27. Main.Global.長案=true;
  28. Main.Global.deleytime=0f;
  29. }
  30. }
  31. }else if (Input.GetMouseButtonUp(0) || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended)){
  32. Main.Global.deleytime=0f;
  33. isPressing = false;
  34. pressDuration = 0f;
  35. }
  36. }
  37. }