- Home /
Building structures inside of eachother. What do i use to stop this?
I have a really simple problem, when im building houses they can be built inside of eachother. I've done it before and i fixed it in like 5 minutes. But the way i did it back then doesnt work now. I Used OnTriggerEnter, but somehow the script doesnt detect the other structures. And yes IsTrigger is ticked and the houses have colliders. It's super weird. So i tried to just check the distance, but it only checks the last placed house distance. What can i do instead of all this? And why is it not detecting the trigger?
Here is what im using now if u need it:
allStructures = GameObject.FindGameObjectsWithTag ("Structure");
for (int i = 0; i < allStructures.Length; i++) {
float dist = Vector3.Distance (transform.position, allStructures [i].transform.position);
if (dist < buildDist) {
canBuild = false;
} else if (allStructures == null) {
canBuild = true;
}
else if(dist > buildDist) {
canBuild = true;
}
}
if (canBuild) {
GetComponent<MeshRenderer> ().material.color = blue;
} else {
GetComponent<MeshRenderer> ().material.color = red;
}
A gameObject needs to have both a collider and a non-kinematic RigidBody (or CharacterController) in order to register collisions with other colliders.
Really? currently its a gameobject with colliders following the mouse on the ground.