A
A
Andrey Yakovenko2016-07-12 02:47:13
Programming
Andrey Yakovenko, 2016-07-12 02:47:13

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

2 answer(s)
K
kestik, 2016-07-12
@divinity2000

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")
      );
    }
  }
 
}

G
GreatRash, 2016-07-12
@GreatRash

docs.unity3d.com/ru/current/Manual/PositioningGame... (look for the "Snap to Grid" paragraph there)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question