Hello there!
I try to cast a sphere around a hit.point and identify, whether there are already other objects within that sphere with a specific tag (XMark). If not, an object should be spawned. Does Physics.OverlapSphere maybe not work if instantiated objects? Or am i getting it wrong? From what i find on the internet this should work :-/ Maybe anyone of you can give me a hint how i can do it right?
Thanks a million!
Here is the Code:
MarkXPosition = hit.point;
// Physics.OverlapSphere(center, radius);
Collider[] MarkXFindSphere = Physics.OverlapSphere(MarkXPosition, 5f);
Debug.Log("Checking if XMarks exist closeby ");
foreach (Collider Test in MarkXFindSphere)
{
if (Test.gameObject.tag != ("XMark"))
{
Debug.Log("No XMarks found nearby, spawning one");
Instantiate(XMark, MarkXPosition, XMark.transform.rotation);
}
else
{
Debug.Log("An XMark already exists nearby! Not spawning XMark");
}
}