I am trying to make a hitbox. So if I hit space while an object is inside my hitbox it will be destroyed. I did a quick search and found this.
It provided some code on how to destroy within a sphere. I modified it and got this:
if(condition == true) {
Collider[] nearObjects = Physics.OverlapSphere(transform.position, 3); //Return an array of all the colliders within a certain radius of some obj. foreach (Collider object in nearObjects) { //Iterate through the array if(object.tag == "enemy") //Does the object have a certain tag. Destroy(object.gameObject); //If yes, then Destroy the gameObject the collider is attached to }
}
But I am getting all sorts of errors (original version got errors too). Can someone tell me why?
P.S. Errors include:
" ; expected. Insert a semicolon…"
“Unexpecte token:)”
“expecting ), found ‘object’”
etc…