您当前的位置: 首页 >  unity

苍狼王unity学院

暂无认证

  • 1浏览

    0关注

    305博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

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

苍狼王unity学院 发布时间:2022-09-04 13:09:44 ,浏览量:1

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

 

关注
打赏
1665389160
查看更多评论
立即登录/注册

微信扫码登录

0.1980s