Answer the question
In order to leave comments, you need to log in
Rounding Unity3d coordinates?
Hello.
There was a problem. Once upon a time I found a script that allows you to move objects along integer coordinates. How can I write this or who can share?
Answer the question
In order to leave comments, you need to log in
wiki.unity3d.com/index.php?title=SnapToGrid
This script should be placed in the Editor folder
using UnityEngine;
using UnityEditor;
using System.Collections;
public class SnapToGrid : ScriptableObject {
[MenuItem ("Window/Snap to Grid %g")]
static void MenuSnapToGrid() {
foreach (Transform t in Selection.GetTransforms(SelectionMode.TopLevel | SelectionMode.OnlyUserModifiable)) {
t.position = new Vector3 (
Mathf.Round(t.position.x / EditorPrefs.GetFloat("MoveSnapX")) * EditorPrefs.GetFloat("MoveSnapX"),
Mathf.Round(t.position.y / EditorPrefs.GetFloat("MoveSnapY")) * EditorPrefs.GetFloat("MoveSnapY"),
Mathf.Round(t.position.z / EditorPrefs.GetFloat("MoveSnapZ")) * EditorPrefs.GetFloat("MoveSnapZ")
);
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question