Simple code is not working? Array,List, and more.

On, the first debug, I get a result, but for some reason, I a getting nothing on the second. Even though practically everything in the test scene is under the correct layer.

private var goArray : GameObject[];
private var objectsOfLayer = new List.<GameObject>();


function Awake(){

    goArray = FindObjectsOfType(GameObject);
    Debug.Log(goArray.Length);
    for(i = 0;i<goArray.Length;i++){
    	if(goArray*.layer == 1<<4){*

_ objectsOfLayer.Add(goArray*);_
_
Debug.Log(“objectsOfLayeradded1”);_
_
}_
_
}_
_
}*_

I think it’s because you’re confusing the layer comparison with mask construction. The bitshifting is only when you want to construct a mask to perform hit testing against during ray casts, where the actual integer value has no meaning, but “layer 4” is valid when the 4th bit is set. Bitshifting 1 << 4 will equal 1000b, which is equal to 1*2^4 = 16. Did you mean to test against layer 16? If not, just put:

if(goArray*.layer == 4)*

Instead.