Created
November 11, 2018 12:52
-
-
Save OhkuboSGMS/81e409393a67d114ed24347040e8de3d to your computer and use it in GitHub Desktop.
RectTransformUtility.ScreenPointToLocalPointInRectangleではまった
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.EventSystems; | |
using UnityEngine.UI; | |
namespace EscapeRoom.LogicImplement | |
{ | |
public class EyeStone : Selectable ,IDragHandler | |
{ | |
public Item Item; | |
private bool _canDrag = false; | |
private RectTransform _transform; | |
private void Start() | |
{ | |
_transform = GetComponent<RectTransform>(); | |
} | |
public override void OnPointerUp(PointerEventData eventData) | |
{ | |
_canDrag = false; | |
} | |
public override void OnPointerEnter(PointerEventData eventData) | |
{ | |
_canDrag = true; | |
} | |
public override void OnPointerExit(PointerEventData eventData) | |
{ | |
_canDrag = false; | |
} | |
public void OnDrag(PointerEventData eventData) | |
{ | |
Vector2 localPos = Vector2.zero; | |
var ii =RectTransformUtility.ScreenPointToLocalPointInRectangle( | |
transform .parent .GetComponent<RectTransform>(), | |
eventData.position, | |
Camera.main, | |
out localPos | |
); | |
_transform.localPosition = localPos; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment