establish DragCube Script mounted in Cube upper
The code is as follows
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class DragCube: MonoBehaviour { private Camera cam;// A camera that emits rays private
GameObject go;// Objects collided by rays public static string btnName;// The name of the object that the ray collides with private Vector3
screenSpace; private Vector3 offset; private bool isDrage = false; Vector3
scale; void Start() { cam = Camera.main; scale = gameObject.transform.localScale
; } void Update() { // Overall initial position Ray ray = cam.ScreenPointToRay(Input.mousePosition)
; // The ray from the camera to the click coordinates RaycastHit hitInfo; if (isDrage == false) { if (Physics.
Raycast(ray, out hitInfo)) { // Draw out the rays , Only in scene View 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, screenSpace.z)); // The name of the object btnName = go.name; // The name of the component } 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; } if (Input.GetAxis("Mouse ScrollWheel") < 0) { //if
(Camera.main.fieldOfView <= 100) // Camera.main.fieldOfView += 2; if (scale.x<5)
{ scale.x += 0.2f; scale.y += 0.2f; scale.z += 0.2f; gameObject.transform.
localScale= scale; } } //Zoom in if (Input.GetAxis("Mouse ScrollWheel") > 0) {
// Zoom camera angle fieldOfView value //if (Camera.main.fieldOfView > 40) //
Camera.main.fieldOfView -= 2; // Zoom objects if (scale.x > 0) { scale.x -= 0.2f; scale.y
-= 0.2f; scale.z -= 0.2f; gameObject.transform.localScale = scale; } } } }

Technology
©2019-2020 Toolsou All rights reserved,
experiment 11-1-6 Output string at specified position (20 branch )vue monitor Treeselect Change of options use PyMC3 Bayesian statistical analysis was performed ( code + example ) Science fiction comes true !“ Trisomy ” Found out Redis Counter High concurrency applications SpringMVC Frame in controller Layer gets the property value of the custom configuration file SQL Server Database Glossary Novices play hiss HI3520D Development board ( One , upgrade ) The project followed for a year , The customer finally said no ToastUtils Use of