- Home /
Strange bug with snapping in editor
I've written some code to help drag hex tiles to proper positions. It works fine, but there's a little annoying detail. I can't zero Z position. Snapping doesn't work when I remove comment signs. So I've add reseting Z position on mouse up event, but still, it isn't satisfying solution. I can't see object when I move it.
[CustomEditor(typeof(Hex))]
public class EHex : Editor {
readonly float ratio = 0.25f * Mathf.Sqrt(3);
void OnSceneGUI() {
Hex tile = target as Hex;
if(Event.current.type == EventType.MouseDrag && Event.current.button == 0) {
var position = Camera.current.ScreenToWorldPoint(Event.current.mousePosition);
position.x = 0.75f * Mathf.Floor(position.x / 0.75f);
position.y = -ratio * Mathf.Floor(position.y / ratio);
//position.z = 0f;
tile.transform.position = position;
}
if(Event.current.type == EventType.MouseUp && Event.current.button == 0) {
var position = tile.transform.position;
position.z = 0f;
tile.transform.position = position;
}
}
}
Any suggestion what is happening? Unity 5.5.4f1
Comment
Your answer
Follow this Question
Related Questions
Unity2D- Screen view out of frustum? 1 Answer
Field of View stuck on screen 0 Answers
Unity 5.6 Google Cardboard Camera Movement Issue 3 Answers
GameObject won't appear in Game view 2 Answers
How can I make a custom 3d editor within the Unity editor? 1 Answer