How to find layer instead of tags

OK, I want to do the same as the code is down but finding the layer This is what I want to do but with layer:

var walls = GameObject.FindGameObjectsWithTag("Walls");
//Important this part "s" because I am searching more than 1 object

So I am searching to do exactly the same(I mean also searching for more objects) but using layer so the question is, how can I do this?

There's no function for that, so you'd have to write your own function to get all game objects and loop through them to see if they're the desired layer, and make an array from the correct ones.

You could use Physics.OverlapSphere with a real great radius to cover the whole scene. It will return only those GameObjects that have a Collider attached but at least you can specify a layermask. OverlapSphere does just a check against the objects AABB (axis aligned bounding box) so i guess it's quite fast.

function FindGameObjectsWithLayer (layer : int) : GameObject {
var goArray = FindObjectsOfType(GameObject);
var goList = new System.Collections.Generic.List.();
for (var i = 0; i < goArray.Length; i++) {
if (goArray*.layer == layer) {*
if (goList.Count == 0) {
return null;
return goList.ToArray();