当前位置:网站首页>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;
}
}
边栏推荐
- JS逆向案例:破解登录密码
- debezium
- Phoenix index
- 论文中英文大小写、数字与标点的正确撰写方式
- mtb13_Perform extract_blend_Super{Candidate(PrimaryAlternate)_Unique(可NULL过滤_Foreign_index_granulari
- Mining pit record of modified field information in Dameng database
- FPGA notes -- implementation of FPGA floating point operation
- Atlas200dk brush machine
- ADC acquisition noise and comparison between RMS filter and Kalman filter
- 每日一问:线程和进程的区别
猜你喜欢

QT excellent open source project 9: qtox

Web學習之TypeScript

Binary sort tree

Optimized three-dimensional space positioning method and its fast implementation in C language

Redisson 3.17.4 发布

1-9Vmware中网络配置
![[image detection] vascular tracking and diameter estimation based on Gaussian process and Radon transform with matlab code](/img/1d/511dceb9decd73976d577af991afc9.png)
[image detection] vascular tracking and diameter estimation based on Gaussian process and Radon transform with matlab code

ciscn_ 2019_ en_ two

统一网关Gateway

AD20(Altium Designer) PCB 高亮网络
随机推荐
DPVS fullnat mode kept
C#另外一个new类的方式Ico?以及App.config的使用
Spark log analysis
Drag the mouse to rotate the display around an object
flink报错:No ExecutorFactory found to execute the application
[OEM special event] in the summer of "core cleaning", there are prize papers
jarvisoj_ level2_ x64
Establish a j-link GDB cross debugging environment for Px4
SQL to retain the maximum value sorted by a field
Android cache usage tool class
Law and self-regulation in the meta universe
Chapter V exercises (124, 678, 15, 19, 22) [microcomputer principles] [exercises]
Summary of push-pull output and open drain output of STM32 and failure of analog IIC driving mlx90615
react + router 框架下的路由跳转后缓存页面存初始参数
Chapter VI exercises (678) [microcomputer principles] [exercises]
About EF page turning query database
debezium
[TSP problem] solving traveling salesman problem based on Hopfield neural network with matlab code
4 key points to help the product manage the project well
Qt之自定义带游标的QSlider