Drawing an overlay grid?

I’m trying to draw an overlay grid that can move around. Is this possible and if so, how can I do it? Thanks :).


alt text

Of course it’s possible.

There may be several ways to do it. If your game is a 2D game, you can either have one sprite for the entire grid, or several small sprites, one for each square, depending on whether or not your grid is constant in size.

If it’s a 3D game, you can create a mesh shaped like the grid, and have a tiled texture on it. Again, this is if the grid is fixed side, otherwise you can create many small meshes. You can use sprites in a 3D game too.

Last option that comes to mind, and the preferred one IMO, is using Unity’s new Canvas component, in World Space render mode. This allows to create something like a billboard inside the game world, which could work great fro your grid. Inside the canvas you can have a tiled image, and also a mask to prevent the corners from rendering. Otherwise you could use a “Grid Layout Group” and arrange single tile images inside, where the corners will have their “Image” component disabled, while the others will be enabled.

using UnityEngine;

//using System.Collections;

public class Grid : MonoBehaviour
	[ SerializeField ] private Transform _transform;
	[ SerializeField ] private Material _material;
	[ SerializeField ] private Vector2 _gridSize;
	[ SerializeField ] private int _rows;
	[ SerializeField ] private int _columns;
	void Start()
	public void UpdateGrid()
		_transform.localScale = new Vector3( _gridSize.x, _gridSize.y, 1.0f );
		_material.SetTextureScale( "_MainTex", new Vector2( _columns, _rows ) );