Help with destroying within a certain zone...

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…

Your script is JavaScript right? (.js)

The code you’re trying to use is C#, so there are a couple differences in syntax for declaring variables.

C# :

Collider[] nearObjects  = .......
 foreach (Collider object in nearObjects) .........

JS:

var nearObjects : Collider[] = .........
for(var object:Collider in nearObjects)..........