Unity Drag and Drop

你离开我真会死。 提交于 2020-01-03 05:20:33

问题


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

Using Event System or any other way?


回答1:


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.



来源:https://stackoverflow.com/questions/49461955/unity-drag-and-drop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!