Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Tile : MonoBehaviour{
  6. private Vector3 firstPosition;
  7. private Vector3 finalPosition;
  8. private float swipeAngle;
  9.  
  10. // Start is called before the first frame update
  11. void Start(){
  12.  
  13. }
  14.  
  15. // Update is called once per frame
  16. void Update(){
  17.  
  18. }
  19.  
  20. void OnMouseDown(){
  21. //Mendapatkan titik awal sentuhan jari
  22. firstPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  23. }
  24.  
  25. void OnMouseUp(){
  26. //Mendapatkan titik akhir sentuhan jari
  27. finalPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  28. CalculateAngle();
  29. }
  30.  
  31. void CalculateAngle(){
  32. //Menghitung sudut antara posisi awal dan posisi akhir
  33. swipeAngle = Mathf.Atan2(finalPosition.y - firstPosition.y, finalPosition.x - firstPosition.x) * 180 / Mathf.PI;
  34. MoveTile();
  35. }
  36.  
  37. void MoveTile(){
  38. if (swipeAngle > -45 && swipeAngle <= 45){
  39. //Right swipe
  40. Debug.Log("Right swipe");
  41. }
  42. else if (swipeAngle > 45 && swipeAngle <= 135){
  43. //Up swipe
  44. Debug.Log("Up swipe");
  45. }
  46. else if (swipeAngle > 135 || swipeAngle <= -135){
  47. //Left swipe
  48. Debug.Log("Left swipe");
  49. }
  50. else if (swipeAngle < -45 && swipeAngle >= -135){
  51. //Down swipe
  52. Debug.Log("Down swipe");
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement