I want to loop through all instantiated GreyBlocks in the scene. Then be able to determine their x,y locations so I can use them in a RectsOverlap function, if there is one, for custom collision.
There is a separate object which is my character which will also be used in the collision check.
How can I do this?
Here is how I instantiate the grey blocks. They are instantiated according to what is stored in the LevelArray.
for (int x = 0; x < 30; x++)
{
for (int y = 0; y < 16; y++)
{
if (levelArray[x, y] == 2)
{
PackedScene joeScene = (PackedScene)ResourceLoader.Load("res://GameObjects/joe.tscn");
Joe = (Joe)joeScene.Instantiate();
Joe.x = x * 64f;
Joe.y = y * 64f;
Joe.Position = new Vector2((float)(Joe.x), (float)(Joe.y));
AddChild(Joe);
}else if (levelArray[x, y] == 1)
{
PackedScene greyBlock = (PackedScene)ResourceLoader.Load("res://GameObjects/grey_block.tscn");
GreyBlock gb = (GreyBlock)greyBlock.Instantiate();
gb.x = x * 64f;
gb.y = y * 64f;
gb.Position = new Vector2(gb.x, gb.y);
AddChild(gb);