当前位置:网站首页>随便画画的
随便画画的
2022-06-25 22:42: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;
}
}
边栏推荐
- 86. (cesium chapter) cesium overlay surface receiving shadow effect (gltf model)
- Web學習之TypeScript
- Web学习之TypeScript
- Permission design = function permission + Data permission
- 防抖和节流
- Penetration tool -burpsuite
- Idea view unit test coverage
- 信号处理函数内必须使用可重入函数
- Kylin
- Mining pit record of modified field information in Dameng database
猜你喜欢

No executorfactory found to execute the application

mtb13_ Perform extract_ blend_ Super{candidate (primaryalternate) \u unique (nullable filtering \foreign\index\granulati

Atlas200dk brush machine

使用VS2022编译Telegram桌面端(tdesktop)

Run the test program using rknn-toolkit-lite2 for rk3568 development board

Redisson 3.17.4 release

QT excellent open source project 9: qtox

Idea view unit test coverage

Performance leads the cloud native database market! Intel and Tencent jointly build cloud technology ecology

Binary sort tree
随机推荐
Apache基金会正式宣布Apache InLong成为顶级项目
Redux workflow + complete code of small examples
DPVS fullnat mode deployment
Qt优秀开源项目之九:qTox
How to bypass SSL authentication
Summary of common terms and knowledge in SMT chip processing industry
Is camkiia the same as gcamp6f?
1-11Vmware虚拟机常见的问题解决
Deploy Ogg on the same machine and test
Stream data
Mining pit record of modified field information in Dameng database
Law and self-regulation in the meta universe
Preordered clue binary tree
Anti shake and throttling
Resolve thread concurrency security issues
Leetcode 513. Find the value in the lower left corner of the tree
元宇宙中的法律与自我监管
Display unassigned virtual address after easyconnect connection
Learn to identify follow-up questions in dialogue Q & A
论文中英文大小写、数字与标点的正确撰写方式