Skip to content

Instantly share code, notes, and snippets.

Last active September 3, 2020 09:37
What would you like to do?
GridSnapping.cs | GameObject Editor Grid Snapping (Optional: change the float gridSize to set the size of the grid)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GridSnapping : MonoBehaviour
public GameObject target;
Vector3 gridPos;
public float gridSize = 10f;
private void Awake()
gridSize = target.transform.localScale.x * 10f;
void LateUpdate()
gridPos.x = Mathf.Floor(target.transform.position.x / gridSize) * gridSize;
gridPos.y = Mathf.Floor(target.transform.position.y / gridSize) * gridSize;
gridPos.z = Mathf.Floor(target.transform.position.z / gridSize) * gridSize;
target.transform.position = gridPos;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment