当前位置:网站首页>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;
}
}
边栏推荐
- Installation and configuration of gradle environment
- mysql
- 1-10Vmware构建自定义的网络架构
- Preorder and middle order traversal of forest
- AD20(Altium Designer) PCB 高亮网络
- Balanced binary tree AVL
- Binary sort tree
- ciscn_ 2019_ en_ two
- Flink报错:Error: A JNI error has occurred, please check your installation and try again
- 1-9Vmware中网络配置
猜你喜欢
![Chapter V exercises (124, 678, 15, 19, 22) [microcomputer principles] [exercises]](/img/16/d67f38d32af6904a7d0be9f2e5be70.png)
Chapter V exercises (124, 678, 15, 19, 22) [microcomputer principles] [exercises]

jarvisoj_ level2_ x64

"Method not allowed", 405 problem analysis and solution

How to design the product roadmap?

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

.net使用Access 2010数据库

1-10Vmware构建自定义的网络架构

"Seamless" deployment of paddlenlp model based on openvinotm development kit

Idea view unit test coverage

Music spectrum display toy -- implementation and application of FFT in stm32
随机推荐
Performance leads the cloud native database market! Intel and Tencent jointly build cloud technology ecology
Comprehensive introduction to Simulink solver
QT custom QSlider with cursor
Redis的安装及启动
Stream data
mysql cluster
1-9Vmware中网络配置
4 key points to help the product manage the project well
[TSP problem] solving traveling salesman problem based on Hopfield neural network with matlab code
10.2.2、Kylin_ Kylin installation, uploading and decompressing, verifying environment variables, starting and accessing
The development context of Ba Kong Yuan universe industry
信号处理函数内必须使用可重入函数
Nacos注册中心
Chapter V exercises (124, 678, 15, 19, 22) [microcomputer principles] [exercises]
Px4 system terminal for pixhawk
Cloud rendering and Intel jointly create the "core" era of cloud rendering
Preorder and middle order traversal of forest
DPVS fullnat mode deployment
Redisson 3.17.4 release
Should group by be used whenever aggregate functions are used in SQL?