Untitled
unknown
csharp
a year ago
1.3 kB
11
Indexable
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
using UnityEngine.EventSystems;
public class Move : MonoBehaviour
{
private RectTransform rectTransform;
public RectTransform slotTransform;
private bool Drag = false;
public bool Dragable = true;
private bool ondrop = false;
GameObject slotObject;
void Start()
{
}
void Awake()
{
rectTransform = GetComponent<RectTransform>();
}
void Update()
{
if (Drag)
{
transform.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
}
}
public void StartDrag()
{
if (!Dragable) return;
Drag = true;
}
public void StopDrag()
{
Drag = false;
float distance = Vector3.Distance(slotTransform.anchoredPosition, rectTransform.anchoredPosition);
print(distance);
if (distance == 0)
{
Dragable = false;
}
if (distance <= 5)
{
Dragable = false;
rectTransform.anchoredPosition = slotTransform.anchoredPosition;
}
}
}Editor is loading...
Leave a Comment