unity从UI上拖动物体在3D场景里生成

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

b8d3cfb839d140ce8d923aca1359695b.jpg

 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);

猜你喜欢

转载自blog.csdn.net/qq_39646949/article/details/126688294