1、首先,创建一个按钮,当点击按钮拖动后会生成对应的预制件!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using System;
public class DragSpan : MonoBehaviour, IPointerDownHandler
{
//拖拽的物体
private GameObject _objDragSpawning;
//是否正在拖拽
private bool _isDragSpawning = false;
// Update is called once per frame
void Update()
{
if (_isDragSpawning)
{
//刷新位置
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
_objDragSpawning.transform.position = ray.GetPoint(10);