当前位置:网站首页>Casually painted
Casually painted
2022-06-26 00:56:00 【KillJUMP】




using UnityEngine;
public class Grabber : MonoBehaviour {
private GameObject selectedObject;
private void Update() {
if (Input.GetMouseButtonDown(0)) {
if(selectedObject == null) {
RaycastHit hit = CastRay();
if(hit.collider != null) {
if (!hit.collider.CompareTag("drag")) {
return;
}
selectedObject = hit.collider.gameObject;
Cursor.visible = false;
}
} else {
Vector3 position = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.WorldToScreenPoint(selectedObject.transform.position).z);
Vector3 worldPosition = Camera.main.ScreenToWorldPoint(position);
selectedObject.transform.position = new Vector3(worldPosition.x, 0f, worldPosition.z);
selectedObject = null;
Cursor.visible = true;
}
}
if(selectedObject != null) {
Vector3 position = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.WorldToScreenPoint(selectedObject.transform.position).z);
Vector3 worldPosition = Camera.main.ScreenToWorldPoint(position);
selectedObject.transform.position = new Vector3(worldPosition.x, .25f, worldPosition.z);
if (Input.GetMouseButtonDown(1)) {
selectedObject.transform.rotation = Quaternion.Euler(new Vector3(
selectedObject.transform.rotation.eulerAngles.x,
selectedObject.transform.rotation.eulerAngles.y + 90f,
selectedObject.transform.rotation.eulerAngles.z));
}
}
}
private RaycastHit CastRay() {
Debug.Log(Input.mousePosition.x);
Camera camera_ = GetComponent<Camera>();
Debug.Log(GetComponent<Camera>().farClipPlane);
Vector3 screenMousePosFar = new Vector3(
Input.mousePosition.x,
Input.mousePosition.y,
GetComponent<Camera>().farClipPlane);
Vector3 screenMousePosNear = new Vector3(
Input.mousePosition.x,
Input.mousePosition.y,
GetComponent<Camera>().nearClipPlane);
Vector3 worldMousePosFar = camera_.ScreenToWorldPoint(screenMousePosFar);
Vector3 worldMousePosNear = camera_.ScreenToWorldPoint(screenMousePosNear);
RaycastHit hit;
Physics.Raycast(worldMousePosNear, worldMousePosFar - worldMousePosNear, out hit);
Debug.Log(hit.collider);
return hit;
}
}
边栏推荐
- Msp430f5529lp official board (red) can not debug the problem
- ciscn_ 2019_ en_ two
- 每日一问:线程和进程的区别
- Reentrant functions must be used within signal processing functions
- 统一网关Gateway
- 10.2.2、Kylin_ Kylin installation, uploading and decompressing, verifying environment variables, starting and accessing
- Why is it best to use equals for integer comparisons
- [TSP problem] solving traveling salesman problem based on Hopfield neural network with matlab code
- SQL to retain the maximum value sorted by a field
- C IO stream (I) basic concept_ Basic definition
猜你喜欢

Flink报错:Error: A JNI error has occurred, please check your installation and try again

Msp430f5529lp official board (red) can not debug the problem

Idea set the template of mapper mapping file

Blob

Compile the telegraph desktop side (tdesktop) using vs2022

Kylin

How to deliver a shelter hospital within 48 hours?

Web學習之TypeScript

AD20(Altium Designer) PCB 高亮网络

Wireshark's analysis of IMAP packet capturing
随机推荐
Anti shake and throttling
1-10vmware builds customized network architecture
1-9network configuration in VMWare
Compile the telegraph desktop side (tdesktop) using vs2022
每日一问:线程和进程的区别
. user. PHP website installation problems caused by INI files
How product managers control the progress of product development
Web學習之TypeScript
Endnote IEEE TRANSACTIONS ON INDUSTRIAL ELECTRONICS/TIE/TPEL 参考文献格式模板
Learn to identify follow-up questions in dialogue Q & A
About the use of hc-12 radio frequency module
[TSP problem] solving traveling salesman problem based on Hopfield neural network with matlab code
Electronic training.
Should group by be used whenever aggregate functions are used in SQL?
Understanding of prototypes and prototype chains
关于EF翻页查询数据库
事物/现象/事情/东西/情况/表象
Drag the mouse to rotate the display around an object
CXF
.net使用Access 2010数据库