Hello guys,
I have a problem with this code:
public int counterA = 0;
public int counterB = 0;
void FixedUpdate()
{
counterA = 0;
counterB = 0;
Vector3 vec = new Vector3();
foreach (GameObject obj in GameObject.FindGameObjectsWithTag("Block"))
{
counterA++;
foreach (GameObject obj2 in GameObject.FindGameObjectsWithTag("Block"))
{
counterB++;
vec = new Vector3(obj2.transform.position.x,obj2.transform.position.y,obj2.transform.position.z);
}
if ((counterA != counterB) && (new Vector3(obj.transform.position.x,obj.transform.position.y,obj.transform.position.z) == vec))
{
DestroyObject(obj);
}
}
}
This code should delete one Block if he has the same Position as any other already placed block with the Tag “Block”.
Problem: It always deletes both Blocks. And i can only place one block. If i place another Block anywhere else it gets deleted immediatly
Hope you can help me…
Greetings,
Markus