Skip to content

Instantly share code, notes, and snippets.

@OhkuboSGMS
Created November 11, 2018 12:52
Show Gist options
  • Save OhkuboSGMS/81e409393a67d114ed24347040e8de3d to your computer and use it in GitHub Desktop.
Save OhkuboSGMS/81e409393a67d114ed24347040e8de3d to your computer and use it in GitHub Desktop.
RectTransformUtility.ScreenPointToLocalPointInRectangleではまった
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