288

Share

GAME DEVELOPMENT

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

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

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.

Agnesh Pipaliya

July 5, 2022

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.

 

 

Step - 1: Create Project

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.

 

 

Step - 2: Create Script

Now create new C# script and give name what you like, in my case i am just save this with names like “MyDragAndDrop.cs”.

Step - 3: Click Detection

First of all you need to enter the code required to detect the gameobject when we clicked on it.

Step - 4: Update Method

Now just copy this code and paste in to the Update method.

Step - 5: Apply Script

Apply this script onto “MyDragAndDrop” GameObject.

 

 

Step - 6: Testing Demo

Now run the scene and drag and drop gameobject that you want to move. You will see this is working fine.

Conclusion

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. 

 

img

Agnesh Pipaliya

COO of Vasundhara Infotech, a leading Software development company in the USA. His technological interests has helped the company in making useful decisions.

message

Have a project in mind? Drop a message to Bansi Pipaliya & start the discussion!

Get a Newsletter

Sign Up to our newsletter to get latest updates staight in your inbox.

Vasundhara respects your privancy. No Spam!

Get a Newsletter

Sign Up to our newsletter to get latest updates staight in your inbox.

Vasundhara respects your privancy. No Spam!

message

Have a project in mind? Drop a message to Bansi Pipaliya & start the discussion!

Latest 13 Web Development Trends To Expect In 2022
April 11, 2022 Category : company news

Revealing Vasundhara’s New Identity

Read More
Leave a Comment