private GameObject InitGrid(Transform parent) { GameObject go = new GameObject(); go.name = "Grid"; go.transform.SetParent(parent, false); go.SetActive(showGrid); int width = source.texture.width + 1; int height = source.texture.height + 1; // set dots texture Texture2D texture = new Texture2D(width, height, TextureFormat.ARGB32, false); texture.filterMode = FilterMode.Point; DrawUtils.ClearTexture(texture); DrawUtils.DrawGrid(texture, tileWidth, tileHeight, new Color(0, 0, 0, 0.1f)); texture.Apply(); // create sprite SpriteRenderer spriteRenderer = go.AddComponent <SpriteRenderer>(); spriteRenderer.sortingOrder = 0; Sprite sprite = Sprite.Create(texture, new Rect(0, 0, width, height), new Vector2(0f, 1f), 1); sprite.name = "DotsSprite"; spriteRenderer.sprite = sprite; return(go); }