This is a drag object. Code , Which is concise and clear. It helps you understand the unity3d script concept! Add comments here to share! VaR mouseovercolor = color. blue; // declare the variable to Blue private var originalcolor: color; // declare the variable to store the original color function start () {originalcolor = Renderer. sharedmaterial. color; // get the object color at the beginning} function onmouseenter () {Renderer. material. color = mouseovercolor; // when the mouse slides, the color of the object is changed to blue.} function onmouseexit () {Renderer. material. color = originalcolor; // restores the original color of the object when the mouse slides out.} function onmousedown () {var screenspace = camera. main. worldtoscreenpoint (transform. position); // convert 3D object coordinates to screen coordinates // convert the mouse screen coordinates to three-dimensional coordinates, and then calculate the distance between the object position and the mouse var offset = transform. position-camera. main. screentoworldpoint (vector3 (input. mouseposition. x, input. mouseposition. y, screenspace. z); print ("down"); While (input. getmousebutton (0) {// print ("button0"); var curscreenspace = vector3 (input. mouseposition. x, input. mouseposition. y, screenspace. z); var curposition = camera. main. screentoworldpoint (curscreenspace) + offset; transform. position = curposition; yield; // This is very important, loop execution }}