how can i count gameObject in a specific Layer that my own give its name?

hi guys ,

normally , with above code, i can count game objects in the scene , if they have their tag .

code : GameObject.FindGameObjectsWithTag(“ExampleGameObject”);

but i don’t want that.I want to count all gameObjects in a specific layer that my own give its name.

can i do this ? Has somebody any idea ?

sory, i have written incomplate question .
Only i don’t want to count these game objects. Additionally , i want to assign these game objects a game object array.

How can i these ?

It is best you use tags instead of layers. Layers are mostly used by cameras and raycasting – and gameObject can only search by tags.

You can put the resulting array (as the function returns an array) into a variable and work with that.

can you little open up this ?

meanwhile thanks for your answer.

This page has all the information you need :slight_smile:

thanx,

i have already done gameobject with tag. But i don’t want this. I have said above so my first question.I want to count all gameObjects in a specific layer that my own give its name.

can i do this ?

You can gather all the gameObjects in the scene into an array and check their layer manually (which is what FindGameObjectsWithTag does for you, but with tags) – still, both operations are costy.

i’m doing so. But it is not being,too. so with array