How To Do Drag And Drop Game Objects With The Mouse In Unity

- Jul 5, 2022
Steps
You have played many games on your smartphone, tablet, or laptop. And you have observed that we need the mouse to move a game object from one place to another.
To drag and drop an object, the mouse is a common mechanic that is used differently in various games. For instance, clicking and moving inventory items in the game world.
Here is the basic guide to learning to drag and drop game objects with a mouse.
First of all create a brand new unity 3D project and set the scene as shown below. Take an empty game object and name it as MyDragAndDrop and create some other game objects like sphere, cube, etc.
Now create new C# script and give name what you like, in my case i am just save this with names like “MyDragAndDrop.cs”.
First of all you need to enter the code required to detect the gameobject when we clicked on it.
Now just copy this code and paste in to the Update method.
Apply this script onto “MyDragAndDrop” GameObject.
Now run the scene and drag and drop gameobject that you want to move. You will see this is working fine.
This beginner's guide will help you develop a simple drag-and-drop game object with a mouse. And you will be able to create this feature on the Unity platform.
Copyright © 2025 Vasundhara Infotech. All Rights Reserved.