- Home /
overlapping object doesn't disable
I want to have objects around another object. For example a cube with layer 9 and four cubes at each side except the top and bottom side, those cubes uses layer 10. If a cube with layer 10 is at the same position as another layer 9 cube or another layer 10 cube it should disable the meshrenderer. I know the logic, but I fail every time when I want to create it.
Scripts I used:
First script is used to run through all tiles and disable the meshrenderer, boxcollider and script to instantiate a tile (object).
public void RunThroughTiles() {
foreach (GameObject tile in tileObjects)
{
foreach (GameObject tile1 in tileObjects)
{
if (tile.transform.position == tile1.transform.position && tile1.layer == 10 && tile != tile1) {
tile1.GetComponent<MeshRenderer>().enabled = false;
tile1.GetComponent<BoxCollider>().enabled = false;
tile1.GetComponent<InstantiateTile>().enabled = false;
Debug.Log("Done");
}
if (tile.transform.position == tile1.transform.position && tile1.layer == 9 && tile != tile1) {
tile.GetComponent<MeshRenderer>().enabled = false;
tile.GetComponent<BoxCollider>().enabled = false;
tile.GetComponent<InstantiateTile>().enabled = false;
Debug.Log("Done1");
}
}
}
}
I have a list of objects named tileObjects every time a tile (object) got instantiated it adds it to that list.
I don't know what I do wrong.
Pictures:
The first picture is how it looks now:
The second picture is how it should look (I did this manually):
The transparent green objects (they uses layer 10) can be pressed to instantiate a land tile (land tiles uses layer 9).
I want to always have a circle of green transparent objects (the same as on the second picture) around a land tile, but not if the green transparent object would overlap something else. How?
You have to know: if a land tile is instantiated the green objects around it while be instantiated too.
Your answer
Follow this Question
Related Questions
overlapping object doesn't disable 1 Answer
Checking if object intersects? 1 Answer
Instantiate an object every x meters between two others. 1 Answer
Rotate the Object 90 Degrees 1 Answer
Distribute terrain in zones 3 Answers