- Home /
Question by
AhmedGalal1987 · Aug 30, 2019 at 05:10 PM ·
unity 2dtexture2dsize
how to make texture2d grid cells smaller ?
hello,
i try to make a grid plane and i follow some tutorial to do it but i want the size of these squares more smaller and change its size .. how can i do that ??
This is my code :
void CreateMap()
{
mapObject = new GameObject("Map");
mapRenderer = mapObject.AddComponent<SpriteRenderer>();
mapObject.tag = "element";
grid = new Node[maxWidth, maxHeight];
Texture2D txt = new Texture2D(maxWidth, maxHeight);
for (int x = 0; x < maxWidth; x++) {
for (int y = 0; y < maxHeight; y++)
{
Vector3 tp = Vector3.zero;
tp.x = x;
tp.y = y;
Node n = new Node()
{
x = x,
y = y,
worldPosition = tp
};
grid[x, y] = n;
availableNodes.Add(n);
if (x % 2 != 0) {
if (y % 2 != 0)
{
txt.SetPixel(x, y, color1);
}
else {
txt.SetPixel(x, y, color2);
}
}
else
{
if (y % 2 != 0)
{
txt.SetPixel(x, y, color2);
}
else
{
txt.SetPixel(x, y, color1);
}
}
}
}
txt.filterMode = FilterMode.Point;
txt.Apply();
Rect rect = new Rect(0, 0 , maxWidth, maxHeight);
Sprite sprite = Sprite.Create(txt, rect, Vector2.zero, 1, 0, SpriteMeshType.FullRect);
mapRenderer.sprite = sprite;
}
And this is the current result :
snakegrid.jpg
(24.4 kB)
Comment