using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class testfordrag : MonoBehaviour,IDragHandler,IPointerDownHandler,IPointerUpHandler,IEndDragHandler{
public RectTransform canvas;
private RectTransform textRect;
Vector2 offset = new Vector2 ();
void Start(){
textRect = GetComponent<RectTransform> ();
}
public void OnPointerDown(PointerEventData eventData){
Vector2 mouseDown = eventData.position;
Vector2 mouseUguiPos = new Vector2 ();
bool isRect = RectTransformUtility.ScreenPointToLocalPointInRectangle (canvas, mouseDown, eventData.enterEventCamera, out mouseUguiPos);
if (isRect) {
offset = textRect.anchoredPosition - mouseUguiPos;
}
}
public void OnDrag(PointerEventData eventData)
{
Vector2 mouseDrag = eventData.position;
Vector2 uguiPos = new Vector2 ();
bool isRect = RectTransformUtility.ScreenPointToLocalPointInRectangle (canvas, mouseDrag, eventData.enterEventCamera, out uguiPos);
if (isRect) {
textRect.anchoredPosition = offset + uguiPos;
}
}
public void OnPointerUp(PointerEventData eventData)
{
offset = Vector2.zero;
}
public void OnEndDrag(PointerEventData eventData)
{
offset = Vector2.zero;
}
void Update(){
GetComponent<Text> ().text = GetComponentInParent<fighter> ().ShowCard ();
}
}
网友评论