Add a Cube object and mount the script in the scene, in addition to the default camera and light.
1 usingSystem.Collections;2 usingSystem.Collections.Generic;3 usingUnityengine;4 5 Public classColliderdemo:monobehaviour {6 7 Private voidOnmousedrag ()8 {9Vector3 v =input.mouseposition;Ten floatf =Input.getaxis (axisname.mousescrollwheel); OneTransform.position + = Transform.forward * F *10f; AV.z = Mathf.abs (Camera.main.transform.position.z-transform.position.z); - Debug.Log (Input.getaxis (Axisname.mousescrollwheel)); -GameObject.transform.localPosition =Camera.main.ScreenToWorldPoint (v); the } -}
It is worth noting that the Screentoworldpoint method does not assign a value to the z-axis, so you need to assign a value to the z-axis yourself. V.z is not the z axis of the cube but the distance between the camera and the cube.
:
Drag and drop objects in unity, and the wheel controls the effect of the object's proximity