Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- public class screenwheel : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
- {
- public Transform onsol;
- public Transform onsag;
- public WheelCollider onsolwc;
- public WheelCollider onsagwc;
- Vector3 position1;
- Quaternion rotation1;
- Vector3 position2;
- Quaternion rotation2;
- float wheelPrevAngle;
- float wheelDragAngle;
- float previous_wheelDragAngle;
- Vector2 centerPoint;
- Vector2 screenPoint2;
- Vector2 firsttouch;
- Vector2 initialtouch;
- Vector2 touchPoint;
- public void OnBeginDrag(PointerEventData eventData)
- {
- centerPoint = RectTransformUtility.WorldToScreenPoint(((PointerEventData)eventData).pressEventCamera, transform.position);
- initialtouch = RectTransformUtility.WorldToScreenPoint(((PointerEventData)eventData).pressEventCamera, eventData.position);
- firsttouch = initialtouch - centerPoint;
- Debug.Log("start touch " + wheelPrevAngle);
- }
- public void OnDrag(PointerEventData eventData)
- {
- centerPoint = RectTransformUtility.WorldToScreenPoint(((PointerEventData)eventData).pressEventCamera, transform.position);
- Debug.Log(centerPoint);
- touchPoint = RectTransformUtility.WorldToScreenPoint(((PointerEventData)eventData).pressEventCamera, eventData.position);
- Debug.Log(touchPoint);
- wheelDragAngle = Vector2.SignedAngle(firsttouch, touchPoint - centerPoint) + previous_wheelDragAngle;
- Debug.Log(wheelDragAngle);
- }
- public void OnEndDrag(PointerEventData eventData)
- {
- previous_wheelDragAngle = wheelDragAngle;
- }
- private void FixedUpdate()
- {
- onsolwc.steerAngle = wheelDragAngle;
- onsagwc.steerAngle = wheelDragAngle;
- transform.rotation = Quaternion.Euler(0f, 0f, wheelDragAngle);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement