반응형

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); 		 	
    } 
} 

 

반응형

+ Recent posts