Grid System – Unity3D (C#)
Grid system is used mostly in RTS games. Your characters or buildings move on grids. You need a matrix to create a grid system.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
public float cell_size = 2.0f; private float x, y, z; void Start() { x = 0f; y = 0f; z = 0f; } void Update () { 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); } |
©Coffee Break Codes – Grid System – Unity3D (C#)