You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.7 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. public class TapDetector : MonoBehaviour {
  4. public float shortPressTime = 0.5f;
  5. public PlayerController playerScript;
  6. private bool isKeyDown;
  7. private float timeDown = -1f;
  8. private bool isLongDown = false;
  9. // Use this for initialization
  10. void Start() {
  11. //playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>();
  12. }
  13. // Update is called once per frame
  14. void Update () {
  15. if (Input.anyKey) {
  16. if (timeDown == -1f) {
  17. timeDown = Time.time;
  18. }else if (Time.time - timeDown >= shortPressTime) {
  19. if (!isLongDown)
  20. longPressDown();
  21. longPress();
  22. isLongDown = true;
  23. }
  24. }else {
  25. if (timeDown != -1 && Time.time - timeDown < shortPressTime) {
  26. shortPress();
  27. }else if (timeDown != -1) {
  28. longPressUp();
  29. isLongDown = false;
  30. }
  31. timeDown = -1f;
  32. }
  33. }
  34. private void longPressDown() {
  35. //Debug.Log("longPressDown");
  36. //playerScript.linkHook();
  37. }
  38. private void longPress() {
  39. //Debug.Log("holdingKey");
  40. Debug.DrawRay(transform.position, Vector3.up * 20, Color.red);
  41. playerScript.rotatePlayer();
  42. }
  43. private void longPressUp() {
  44. //Debug.Log("LongPressUp");
  45. //playerScript.unlinkHook();
  46. playerScript.movePlayer();
  47. }
  48. private void shortPress() {
  49. //Debug.Log("shorPress");
  50. Debug.DrawRay(transform.position, Vector3.up * 20, Color.green,0.3f);
  51. playerScript.shoot();
  52. }
  53. }