- Home /
How can I instantiate only where there is free space?
I am making an asteroid mining game. I want the player to be able to choose where to place mining stations and solar arrays, missile launchers etc. in the scene by clicking. My question is how can I make it so that the player cannot place objects on top of each other. I think that I might be able to do it with colliders but I am not sure how.
How are you placing the objects? through a grid or just at any position?
If you using a grid just create a list of positions and check whether that position is occupied... If you are placing them randomly then you can use Raycasts and BoxColliders...
Answer by zORg_alex · May 30 at 12:53 PM
You can have a GameObject with trigger Collider and a scritp that should follow mouse and track if it has something inside or not. OnTriggerEnter(Exit) messages will notify you about collisions. So when you are trying to build, check if that script has something colliding with or it's fine to build.