user9543482
user9543482

Reputation: 1

Unity Drag and Drop

How to make a C# drag and drop (for Prefab) script in Unity?

Using Event System or any other way?

Upvotes: 0

Views: 1284

Answers (1)

user9544286
user9544286

Reputation:

You can use UnityEngine.EventSystems.EventTrigger (EventTrigger component) to catch some events like OnDragStarted, OnDrag, OnDragEnded, etc.

Firstly, you need to set this component to object from witch you want to start drag (for example building icon in strategy game). Then set events to some functions, that's implements movement of icon and building placement.

Secondly, you need to implement functions that's places buildings and moves icons while player dragging them.

Also, you can implement interfaces such as IPointerDownHandler to implement this logic.

Upvotes: 1

Related Questions