Created
March 24, 2015 19:09
-
-
Save dnkm/eb789d58204ee3ca882e to your computer and use it in GitHub Desktop.
Grid Snapping
This file contains 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 UnityEngine; | |
using System.Collections; | |
[ExecuteInEditMode] | |
public class SnapToGrid : MonoBehaviour { | |
public float cell_size = 1f; // = larghezza/altezza delle celle | |
private float x, y, z; | |
void Start() { | |
x = 0f; | |
y = 0f; | |
z = 0f; | |
} | |
void Update() { | |
// comment this out before deploying! | |
x = Mathf.Round(transform.position.x / cell_size) * cell_size; | |
y = Mathf.Round(transform.position.y / cell_size) * cell_size; | |
z = transform.position.z; | |
transform.position = new Vector3(x, y, z); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment