I am making an RTS game where you can place buildings by clicking.
When you are placing buildings the outline of the buildings appears on the floor, and if this outline is colliding with anything, you wont be able to place the building. This works if you’re acting normally, however, if you already have a building placed and you’re trying to place a building by continually clicking and spinning the mouse around like a maniac then it is very common for buildings to be placed intersecting each other.
I tested this by being able to place infinite buildings and filling the area up with buildings, obviously not a scenario that should happen in the game, but the bug could still happen if you’re moving your mouse quickly while placing a single building, I guess.
I’ve tried using all 3 of these at once:
function OnTriggerExit() {
canPlace = true;
}
function OnTriggerStay() {
canPlace = false;
}
function OnTriggerEnter() {
canPlace = false;
}
however the issue still occurs.
My guess is that somehow the above functions are called after the update function, in which I have this code:
if (Input.GetMouseButtonDown(0) && canPlace)
Instantiate(placeObjects[placeType], Vector3(mousePos.x, 1, mousePos.z), Quaternion.identity);
But I really have no idea why, sorry this question is so open ended, but what is going on here, and how do I fix it?