hey guys I've been trying to code a part of my game where an object from the library is spawned on top of another object for e.g. a red square is spawned on top of a blue square and a green square on top of the red, when the fourth square is spawned the blue square is deleted and another square is spawned on top such as a yellow square.

There are many different colours and the new square spawning on top of the other is random. I know I have to use an array but don't know how to get the objects directly on top of each other. my character can go through these squares and once my character comes towards the end of a block another one is spawned.