- Home /
how to prevent an gameobject of instantiating if theres an collider where it is supposed to collide
I'm trying to prevent being able to drop items / instantiate items when there is a collider in the way.
It is a 2d game
any help is appreciated.
Answer by N-8-D-e-v · Jul 18, 2020 at 03:27 AM
Try instantiating your objects from a 'spawner' gameobject, then before that object spawns, check if there are any colliders touching it by using Physics2D.OverlapCircleAll https://docs.unity3d.com/ScriptReference/Physics2D.OverlapCircleAll.html which will return an array of colliders. Then you can check if the array contains any colliders, and if it does, move to a different position.
Your answer
Follow this Question
Related Questions
Help On Checking OverLaping in instantiating 0 Answers
Issues getting a BulletTrail to explode on contact Unity2D 0 Answers
OnCollisionEnter2D is not working when an object tagged "Enemy" is not present. 2 Answers
OnTriggerEnter2D being called by GameObject without the trigger 1 Answer
Multiple Cars not working 1 Answer