Physics2D.OverlapCircleAll wont make up its mind
So I am making a Tower Defense game, I can press a button and place down towers but im trying to make it so i cant put them on top of each other which im sure is a pretty simple task. i have tried oncollisionenter and exit but if there are two towers next to each other when i mouse over the first one it calls ontriggerenter just fine and wont let me place the tower, which is correct, but if i mouse over the first one and then the second it calls ontriggerenter while im moving to the second one and then it calls ontriggerexit as i exit the first tower. allowing me to place the tower over an existing tower(I hope i explained that well enough). I am now trying to use Physics2D.OverlapCircleAll, and it works half the time but not the other half. heres my code.
Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, 1f, 1 << 9);
if(colliders.Length > 0)
{
//Colliding with something
Debug.Log("Colliding with something on my layer");
CanPlace = false;
}
if(colliders.Length <= 0)
{
CanPlace = true;
}
if theres a better way to do it please let me know, im sure its pretty simple i just cant seem to figure it out. Thanks!
Your answer
Follow this Question
Related Questions
How to change rigidbody type correctly? Angry Birds Game 1 Answer
Circle Collider Stuck to Box Collider 1 Answer
How to place a sprite on the face of a collider 0 Answers
problem with crouching,Need help with colliders 0 Answers
[Solved] Prevent movement while in the air while keeping momentum. 0 Answers