Last active
April 23, 2021 18:13
-
-
Save unity3dcollege/420a6f3f8e7ba2edaf178d199bd9d938 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEngine; | |
public class SnapToGround : MonoBehaviour | |
{ | |
[MenuItem("Custom/Snap To Ground %g")] | |
public static void Ground() | |
{ | |
foreach(var transform in Selection.transforms) | |
{ | |
var hits = Physics.RaycastAll(transform.position + Vector3.up, Vector3.down, 10f); | |
foreach(var hit in hits) | |
{ | |
if (hit.collider.gameObject == transform.gameObject) | |
continue; | |
transform.position = hit.point; | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment