InputController.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. [RequireComponent(typeof(SwipeManager))]
  5. public class InputController : MonoBehaviour
  6. {
  7. public SwipeMove OurPlayer; // Perhaps your playerscript?
  8. void Start()
  9. {
  10. SwipeManager swipeManager = GetComponent<SwipeManager>();
  11. swipeManager.onSwipe += HandleSwipe;
  12. swipeManager.onLongPress += HandleLongPress;
  13. }
  14. void HandleSwipe(SwipeAction swipeAction)
  15. {
  16. //Debug.LogFormat("HandleSwipe: {0}", swipeAction);
  17. if (swipeAction.direction == SwipeDirection.Up || swipeAction.direction == SwipeDirection.UpRight)
  18. {
  19. // move up
  20. if (OurPlayer != null)
  21. OurPlayer.SlideForward();
  22. }
  23. else if (swipeAction.direction == SwipeDirection.Right || swipeAction.direction == SwipeDirection.DownRight)
  24. {
  25. // move right
  26. if (OurPlayer != null)
  27. OurPlayer.SlideRight();
  28. }
  29. else if (swipeAction.direction == SwipeDirection.Down || swipeAction.direction == SwipeDirection.DownLeft)
  30. {
  31. // move down
  32. if (OurPlayer != null)
  33. OurPlayer.SlideBackward();
  34. }
  35. else if (swipeAction.direction == SwipeDirection.Left || swipeAction.direction == SwipeDirection.UpLeft)
  36. {
  37. // move left
  38. if (OurPlayer != null)
  39. OurPlayer.SlideLeft();
  40. }
  41. else
  42. {
  43. if (OurPlayer != null)
  44. OurPlayer.SlideNone();
  45. }
  46. }
  47. void HandleLongPress(SwipeAction swipeAction)
  48. {
  49. Debug.LogFormat("HandleLongPress: {0}", swipeAction);
  50. }
  51. }