I created special blocks that move around randomly when hit, until all breakable blocks are destroyed – then they are switched to breakable blocks as well.
Now, everything works fine but the moving blocks overlap one another, as their position is set randomly within the scene. I tried making sure that doesn’t happen with Physics.CheckSphere, but I can’t get it to work, it always returns “nothing here”, so it somehow doesn’t seem to “see” the other GameObjects. Can anyone help?
private void MoveBlock()
{
float randX = Random.Range(xMinBoundary, xMaxBoundary);
float randY = Random.Range(yMinBoundary, yMaxBoundary);
Vector2 target = new Vector2(randX, randY);
float radius = 10f;
if (Physics.CheckSphere(target, radius))
{
Debug.Log("found something");
transform.localPosition = target * 20;
}
else
{
Debug.Log("found nothing");
transform.localPosition = target;
}
}