Move Object to Mouse Click Position – Unity3D (C#)


Move Object to Mouse Click Position – Unity3D (C#)

No matter 2D or 3D, we use same method to move an object to mouse click position. We need to get mouse click position on ground or whatever, and move object to this position. Create a plane and a cube. We will move cube to any position on plane with mouse click. We get the mouse click position with Raycast.

Attach this code to plane and assign a cube as public game object. Now, press play and test it. Click anywhere on plane and see cube moving.

©Coffee Break Codes – Move Object to Mouse Click Position – Unity3D (C#)


Leave a comment

Your email address will not be published. Required fields are marked *

2 thoughts on “Move Object to Mouse Click Position – Unity3D (C#)