GameObject Pool heaving difficulties getting a pool at all trying to find different aproach

any small pushes how should I approach this will be helpful thanks in advance

problem is not within the code thing is I wanted to go not to destroy and istantiate a new GO at all

but as soon as I moved to figureing what kind of GO are actually falsed I figured out I’m already destroying a GO so doing all complex for nothing

problem is the first one might never get falsed and the last one will or the other way around

this are not bullets but bricks or what ever that are false ONLY when player picks them up

yes this works smoothly and all but I think it’s even less effective than just destroying a GO and instantiating new one

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

// TRAINING PURPOSES ONLY

public class Pooling : MonoBehaviour {
	public GameObject prefab ;
	public List<GameObject> ActiveCopy ;
	public List<GameObject> DeactiveCopy ;
	public float time = 0;
	public float time1 = 0;
	public float timeremaining = 0.1f ;
	
	public bool NewOne = false ;
	
	void Update (){
		if (! NewOne){
			time = Time.time ;
			NewOne = true ;
		}
		time1 = Time.time ;
		
		if ((time1 - time) > timeremaining){
			
			ActiveCopy.Add(prefab);
			
			ActiveCopy[ActiveCopy.Count-1] = Instantiate( ActiveCopy[ActiveCopy.Count-1] ) as GameObject;
			ActiveCopy[ActiveCopy.Count-1].transform.position = transform.position ;
			ActiveCopy[ActiveCopy.Count-1].transform.parent = transform ;
			
			Deactivate(ActiveCopy.Count-1);
			NewOne = false ;
		}
	}
	
	void Deactivate (int Count) {
		ActiveCopy[Count].SetActive(false) ;
		DeactiveCopy.Add(ActiveCopy[Count]) ;
		ActiveCopy.Remove(ActiveCopy[Count]) ;
	}
}

I didn’t create with

public GameObject[] Copy

because every time I do than

Copy = new GameObject[(IncreasedNumber)]

all GO are simply deleted within Copy and Copy does not contain them any longer while they exist in scene and I can’t track them

I thinked a bit more and heard some times about taggs I don’t even know how does tagging work

all I want is find the object that’s false it doesn’t matter first false or last false one but defenally I don’t want to pick up the true one

they will not get false over time but randomely by player when player picks it up

First instantiate your objects and put them in the list however you’d like.

Example:

List<GameObject> gameObjects = new List<GameObject>();

//instantiate 20 GameObjects and set every other one to inactive
for(int x = 0; x < 20; x++)
{
	//add an instantiated GameObject
	gameObjects.Add((GameObject)Instantiate (prefab, prefab.transform.position, prefab.transform.rotation));
	
	//if a round number then set that object to inactive
	if(x%2 == 0)
	{
		gameObjects[x].active = false;
	}
}

There are a couple ways to find the inactive objects

1 - Loop through and check the Active state.

foreach(GameObject go in gameObjects)
{
	if(go.active)
	{
		//do something with the active GameObject
	}
	else
	{
		//do something with the inactive GameObject
	}
}

2- Using Linq in C#

IEnumerable<GameObject> inactiveGameObjects = System.Linq.Enumerable.Where(gameObjects, n => n.active == false);

foreach(GameObject go in inactiveGameObjects)
{
	Debug.Log(go.name);
}

3- Using Tags in Unity
Set the GameObjects tag by using

yourObject.tag = "TagName";

Then get all GameObjects with tag “TagName” using

GameObject[] inactiveGameObjects = GameObject.FindGameObjectsWithTag("TagName");

Be sure to add the Tag in the Tag/Layer editor in Unity or Unity won’t recognize it as a valid tag.