Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Last active April 23, 2021 18:13
Show Gist options
  • Save unity3dcollege/420a6f3f8e7ba2edaf178d199bd9d938 to your computer and use it in GitHub Desktop.
Save unity3dcollege/420a6f3f8e7ba2edaf178d199bd9d938 to your computer and use it in GitHub Desktop.
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