-
Notifications
You must be signed in to change notification settings - Fork 0
/
CubeEditor.cs
40 lines (34 loc) · 870 Bytes
/
CubeEditor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
[SelectionBase]
[RequireComponent(typeof (Waypoint))]
public class CubeEditor : MonoBehaviour
{
Vector3 gridPos;
Waypoint waypoint;
private void Awake()
{
waypoint = GetComponent<Waypoint>();
}
void Update()
{
SnapGrid();
ShowLabel();
}
private void SnapGrid()
{
int gridSize = waypoint.GetGridSize();
transform.position = new Vector3(
waypoint.GetGridPos().x,
0,
waypoint.GetGridPos().y);
}
private void ShowLabel()
{
int gridSize = waypoint.GetGridSize();
string labelText = waypoint.GetGridPos().x/ gridSize + " , " + waypoint.GetGridPos().y/ gridSize;
gameObject.name = labelText;
}
}