Answer the question
In order to leave comments, you need to log in
How to refer to the spriteRender of an object in an array?
Hello comrades!!!!
There is this code:
public GameObject block;
// public float startPosX;
// public float startPosY;
public int countX;
public int countY;
public float outX;
public float outY;
public string objName = "Block_";
private int id;
public GameObject[,] grid;
// Start is called before the first frame update
void Start()
{
float startPosX = block.transform.position.x;
float startPosY = block.transform.position.y;
id = 0;
float posXreset = startPosX;
grid = new GameObject[countX, countY];
for (int y = 0; y < countY; y++)
{
startPosY -= outY;
for (int x = 0; x < countX; x++)
{
id++;
startPosX += outX;
grid[x, y] = Instantiate(block, new Vector2(startPosX, startPosY), Quaternion.identity) as GameObject;
grid[x, y].name = objName + id;
grid[x, y].transform.parent = transform;//работает
grid[x, y].spriteRenderer.material = null;//не работает
}
startPosX = posXreset;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question