Drag and drop means click and move an object in a game. It is one of the important features of game applications. And Unity is a platform for game development.
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.
COO of Vasundhara Infotech, a leading Software development company in the USA. His technological interests has helped the company in making useful decisions.
Sign Up to our newsletter to get latest updates staight in your inbox.
Vasundhara respects your privancy. No Spam!
Sign Up to our newsletter to get latest updates staight in your inbox.
Vasundhara respects your privancy. No Spam!