- Home /
Question by
Aditya-Rawat · Dec 27, 2021 at 01:37 PM ·
instantiatecolorcorner
To find corner blocks among instantiated blocks
Hello, I want to find the corner blocks among the instantiated blocks in the scene. I want blocks to surround the main path blocks and colorize corner blocks.
This is test code :
public GameObject box;
GameObject[] gameObjects;
private void Awake()
{
gameObjects = GameObject.FindGameObjectsWithTag("Floor");
GetPos();
}
void GetPos()
{
for (int a = 0; a < gameObjects.Length; a++)
{
for (int i = -1; i < 2; i++)
{
for (int j = -1; j < 2; j++)
{
Collider[] col = Physics.OverlapSphere(gameObjects[a].transform.position + new Vector3(i, 0, j), 0.25f);
if (col.Length <= 0)
GenerateBlocks(i, j, a);
}
}
}
}
void GenerateBlocks(int x, int z, int y)
{
GameObject go = Instantiate(box, gameObjects[y].transform.position + new Vector3(x, 0, z), Quaternion.identity);
go.GetComponent<Renderer>().material.color = Color.red;
go.transform.parent = transform;
}
The result: (with 2 path blocks) 
But I want something like this :

Thanks.
blockss2.png
(11.5 kB)
blockssmain.png
(10.5 kB)
Comment
Your answer
Follow this Question
Related Questions
Combination of Instance and random in a network game 2 Answers
Using GetPixel to instantiate blocks of different pixel colors 1 Answer
Instantiating multiple sprites and assigning different colors for each 1 Answer
How to instantiate a prefab and change its color? 5 Answers
Instantiated prefab color change 2 Answers