Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using UnityEngine.UI;
  6.  
  7. public class screenwheel : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
  8. {
  9.  
  10. public Transform onsol;
  11. public Transform onsag;
  12.  
  13. public WheelCollider onsolwc;
  14. public WheelCollider onsagwc;
  15. Vector3 position1;
  16. Quaternion rotation1;
  17. Vector3 position2;
  18. Quaternion rotation2;
  19. float wheelPrevAngle;
  20. float wheelDragAngle;
  21. float previous_wheelDragAngle;
  22. Vector2 centerPoint;
  23. Vector2 screenPoint2;
  24. Vector2 firsttouch;
  25. Vector2 initialtouch;
  26. Vector2 touchPoint;
  27.  
  28. public void OnBeginDrag(PointerEventData eventData)
  29. {
  30.  
  31. centerPoint = RectTransformUtility.WorldToScreenPoint(((PointerEventData)eventData).pressEventCamera, transform.position);
  32.  
  33. initialtouch = RectTransformUtility.WorldToScreenPoint(((PointerEventData)eventData).pressEventCamera, eventData.position);
  34.  
  35. firsttouch = initialtouch - centerPoint;
  36.  
  37. Debug.Log("start touch " + wheelPrevAngle);
  38.  
  39. }
  40.  
  41. public void OnDrag(PointerEventData eventData)
  42. {
  43.  
  44.  
  45. centerPoint = RectTransformUtility.WorldToScreenPoint(((PointerEventData)eventData).pressEventCamera, transform.position);
  46. Debug.Log(centerPoint);
  47.  
  48. touchPoint = RectTransformUtility.WorldToScreenPoint(((PointerEventData)eventData).pressEventCamera, eventData.position);
  49. Debug.Log(touchPoint);
  50.  
  51. wheelDragAngle = Vector2.SignedAngle(firsttouch, touchPoint - centerPoint) + previous_wheelDragAngle;
  52. Debug.Log(wheelDragAngle);
  53.  
  54.  
  55. }
  56.  
  57. public void OnEndDrag(PointerEventData eventData)
  58. {
  59. previous_wheelDragAngle = wheelDragAngle;
  60.  
  61. }
  62.  
  63. private void FixedUpdate()
  64. {
  65.  
  66. onsolwc.steerAngle = wheelDragAngle;
  67. onsagwc.steerAngle = wheelDragAngle;
  68.  
  69. transform.rotation = Quaternion.Euler(0f, 0f, wheelDragAngle);
  70.  
  71. }
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement