Unity 拖动UI物体(超级干货)
首先我们先创建一个C#脚本 名字就叫MyMove
代码如下
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class MyMove: MonoBehaviour
{
public GameObject Canvas;
GameObject InputObject;
bool b;//鼠标是否在按下状态
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//当鼠标按下时 状态为按下状态 InputObject去获取鼠标点击的UI
if (Input.GetMouseButtonDown(0))
{
b = true