InSelecto
InSelecto

Reputation: 21

How to create a custom height snapping tool in Unity Editor

I am making a strategy game and I need to have a tool which places the objects above the terrain while I am dragging them in Unity Editor when I work on level design. Basically I want to get result like here: https://www.youtube.com/watch?v=YI6F1x4pzpg but I need it to work before I hit the Play button in Unity Editor.

Here is a tutorial https://www.youtube.com/watch?v=gLtjPxQxJPk where the author of it made a tool which snaps the object to the terrain height when a key is pressed. I need the same to happen automatically whenever I place an object over my terrain. And I want my tool to adjust the Y position of the object automatically even while I am dragging it inside of the editor.

Also just to clarify: I don't need grid snapping and I don't need this functionality during the gameplay. I just need to have a tool for my level design work.

Please give me a clue where to start with it.

Thanks!

Upvotes: 1

Views: 662

Answers (1)

AlexGeorg
AlexGeorg

Reputation: 1037

There is this tag you can apply to classes so they do call their regular events during editor mode already: https://docs.unity3d.com/ScriptReference/ExecuteInEditMode.html A trivial way then would be to apply this to a special class/object which regularly "finds" all objects from the game object hierarchy. Then it shall filter that list for the ones you want to snap to the axis and enforce their Y.

Upvotes: 1

Related Questions