반응형
using UnityEngine;
using UnityEngine.EventSystems;
using DG.Tweening;
public class WheelHandler : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler {
RectTransform ImgRectTransform;
void Start () {
ImgRectTransform = GameObject.Find("Canvas/Wheel/ImageR").GetComponent();
}
public void OnPointerDown(PointerEventData e){
rotateImage(e.position);
}
public void OnPointerUp(PointerEventData e){
rotateImage(e.position);
}
public void OnDrag(PointerEventData e){
rotateImage(e.position);
}
protected void rotateImage( Vector2 value ){
float _x = value.x - Screen.width/2;
float _y = value.y - Screen.height/2;
float _R;
if(_x > 0){
_R = (Mathf.Atan(_y/_x) * Mathf.Rad2Deg);
}
else
{
_R = (Mathf.Atan(_y/_x) * Mathf.Rad2Deg) + 180;
}
ImgRectTransform.DORotate(new Vector3(0f,0f,_R),0.1f,RotateMode.Fast);
}
}
반응형
'unity C#' 카테고리의 다른 글
[Unity] Bitmap Drawing API 사용해보기 (1) | 2015.11.11 |
---|---|
[Unity] Android Plugins 제작하기 (0) | 2015.10.27 |
[Unity] EventSystem설정 터치 감도 조절 (4) | 2015.10.26 |
[Unity] Hashtable > ArrayList > JsonData (0) | 2015.10.26 |
[Unity] 리스트 재 정렬하기 list resorting (0) | 2015.10.26 |