I want to destroy all objects at a particular location. The way I am currently doing it is:
void DestroyObjectAtLocation(float nX, float nY, float nZ) {
foreach (string strTag in UnityEditorInternal.InternalEditorUtility.tags)
{
GameObject[] tiles = GameObject.FindGameObjectsWithTag (strTag);
foreach (GameObject tile in tiles)
if ((tile.transform.position.z == nZ) && (tile.transform.position.x == nX) && (tile.transform.position.y == nY))
Destroy (tile);
}
}
This works perfectly but seems extremely inefficient. Is there a better way? I am largely a novice so please have mercy on my poor soul .
fafase
2
Use a trigger sphere or box. Place it at the position, make it as large as needed and use:
void OnTriggerEnter(Collider col){
if(col.collider.gameObject.CompareTag(strTag)){Destroy(this.gameObject);}
}
Add this to the tiles and mark the collider as trigger.
wfefrfe
3
void DestroyObjectAtLocation(float nX, float nY, float nZ, float minDist) {
Vector3 tmpLocation = new Vector3 (nX, nY, nZ);
Transform[] tiles = GameObject.FindObjectsOfType<Transform> ();
for (int i = 0; i < tiles.Length; i++) {
if(Vector3.Distance(tiles*.position, tmpLocation) <= minDist){*
_ Destroy(tiles*.gameObject);_
_ }_
_ }_
_ }*_