Advertisemen
In this tutorial, we are going to take a look on how to make unity editor extension that allows you to snap object to the ground. First of all take a look at these then I will explain step by step.
In first picture, what we have in unity is one cube, sphere, plane (for ground), directional light, main camera and C# script name snapToGround (which you don't have to attach to any game object in unity).
In second picture, hope you can see numbers next to each line because I will explain number by number.
Number one indicates you have to add that line to get access to unity editor.
Number two - is for menu item name.
Number three - create function and name it whatever you want, I named mine Snap.
Number four - puts all the selected objects into the array.
Number five - foreach function goes through each object in array just created in number four.
Number six - checks raycasting downward from selected object.
Number seven - gets the position of hit point.
Number eight - checks if selected object has mesh filter in it.
Number nine - collects bounds of selected object.
Number ten - adds half of bounds from y side to targeted object's y position so selected object doesn't go half inside the floor.
Number eleven - converts selected object's position to hit point's position.
Number twelve - last two keep the original rotation value of selected objects.
Advertisemen
Tidak ada komentar:
Posting Komentar