Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerController : MonoBehaviour {
  5.  
  6. public bool button_left_pressed = false;
  7. public bool button_right_pressed = false;
  8. int button_left_fingerid = -1;
  9. int button_right_fingerid = -1;
  10.  
  11. void Update ()
  12. {
  13. foreach (Touch myTouch in Input.touches)
  14. {
  15. if (myTouch.phase == TouchPhase.Began)
  16. {
  17. if (myTouch.position.x > 605f && myTouch.position.x < 905f && myTouch.position.y > 390f && myTouch.position.y < 690f)
  18. {
  19. //Debug.Log("Left");
  20. button_left_pressed = true;
  21. button_left_fingerid = myTouch.fingerId;
  22. }
  23. if (myTouch.position.x > 1114f && myTouch.position.x < 1414f && myTouch.position.y > 390f && myTouch.position.y < 690f)
  24. {
  25. //Debug.Log("Right");
  26. button_right_pressed = true;
  27. button_right_fingerid = myTouch.fingerId;
  28. }
  29. }
  30.  
  31. if (button_left_fingerid != -1)
  32. {
  33. if (myTouch.fingerId == button_left_fingerid)
  34. {
  35. if (myTouch.phase == TouchPhase.Ended || myTouch.phase == TouchPhase.Canceled)
  36. {
  37. button_left_pressed = false;
  38. }
  39. }
  40. }
  41.  
  42. if (button_right_fingerid != -1)
  43. {
  44. if (myTouch.fingerId == button_right_fingerid)
  45. {
  46. if (myTouch.phase == TouchPhase.Ended || myTouch.phase == TouchPhase.Canceled)
  47. {
  48. button_right_pressed = false;
  49. }
  50. }
  51. }
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement