GameObject CloneNewInstance(GameObject prefab, PoolSet pooledSet, Vector3 position, Quaternion rotation) { // Initialized a new GameObject GameObject returnObject = (GameObject)Instantiate(prefab, position, rotation); // Update this object's parent so it won't get destroyed easily returnObject.transform.parent = poolingParent; // Grab the script from the clone if there is any in the original IPooledObject script = null; if (pooledSet.containsPoolScript == true) { script = returnObject.GetComponent <IPooledObject>(); script.OriginalPrefab = prefab; } // Add this new GameObject and script into the dictionary pooledSet.allClonedInstances.Add(returnObject, script); // Indicate to the script the object was initialized if (script != null) { script.Initialized(this); } return(returnObject); }