国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

unity怎么實(shí)現鼠標拖住3D物體

發(fā)布時(shí)間:2021-09-04 11:55 來(lái)源:億速云 閱讀:0 作者:chen 欄目: 開(kāi)發(fā)技術(shù)

本篇內容介紹了“unity怎么實(shí)現鼠標拖住3D物體”的有關(guān)知識,在實(shí)際案例的操作過(guò)程中,不少人都會(huì )遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學(xué)有所成!

把該腳本直接掛在要拖拽的物體上即可

using System.Collections;using System.Collections.Generic;using UnityEngine;public class ModelDrages : MonoBehaviour {//發(fā)射射線(xiàn)的攝像機private Camera cam;//射線(xiàn)碰撞的物體private GameObject go;//射線(xiàn)碰撞物體的名字public static string btnName;private Vector3 screenSpace;private Vector3 offset;private bool isDrage = false;// Use this for initializationvoid Start (){  cam = Camera.main;}// Update is called once per frame  void Update (){  //整體初始位置  Ray ray = cam.ScreenPointToRay(Input.mousePosition);  //從攝像機發(fā)出到點(diǎn)擊坐標的射線(xiàn)  RaycastHit hitInfo;  if (isDrage == false)  {    if(Physics .Raycast (ray,out hitInfo))    {      //劃出射線(xiàn) 只有在Scene視圖中才能看到      Debug.DrawLine(ray.origin, hitInfo.point);      go = hitInfo.collider.gameObject;      print(btnName);      screenSpace = cam.WorldToScreenPoint(go.transform.position);      offset = go.transform.position - cam.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z));      //物體的名字      btnName = go.name;      //組件的名字    }    else    {      btnName = null;    }  }  if(Input.GetMouseButton(0))  {    Vector3 currentScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);    Vector3 currentPosition = cam.ScreenToWorldPoint(currentScreenSpace) + offset;    if (btnName != null)    {      go.transform.position = currentPosition;    }    isDrage = true;  }  else  {    isDrage = false;  } }}

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自互聯(lián)網(wǎng)轉載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權請聯(lián)系QQ:712375056 進(jìn)行舉報,并提供相關(guān)證據,一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容。

欧美精品亚洲精品日韩专区| AV在线播放日韩亚洲欧| AV潮喷大喷水系列无码| 久久99国内精品自在现线| √天堂中文WWW官网| 中文字幕亚洲精品乱码|