diff --git a/Assets/ObjectPool/Scripts/ObjectPool.cs b/Assets/ObjectPool/Scripts/ObjectPool.cs index fba6c17..a67f6b0 100755 --- a/Assets/ObjectPool/Scripts/ObjectPool.cs +++ b/Assets/ObjectPool/Scripts/ObjectPool.cs @@ -118,7 +118,11 @@ public static GameObject Spawn(GameObject prefab, Transform parent, Vector3 posi if (obj != null) { trans = obj.transform; - trans.parent = parent; + if (parent) + { + bool worldPositionStays = (parent.GetComponent () == null) ? true : false; + trans.SetParent (parent, worldPositionStays); + } trans.localPosition = position; trans.localRotation = rotation; obj.SetActive(true); @@ -128,7 +132,11 @@ public static GameObject Spawn(GameObject prefab, Transform parent, Vector3 posi } obj = (GameObject)Object.Instantiate(prefab); trans = obj.transform; - trans.parent = parent; + if (parent) + { + bool worldPositionStays = (parent.GetComponent () == null) ? true : false; + trans.SetParent (parent, worldPositionStays); + } trans.localPosition = position; trans.localRotation = rotation; instance.spawnedObjects.Add(obj, prefab); @@ -138,7 +146,11 @@ public static GameObject Spawn(GameObject prefab, Transform parent, Vector3 posi { obj = (GameObject)Object.Instantiate(prefab); trans = obj.GetComponent(); - trans.parent = parent; + if (parent) + { + bool worldPositionStays = (parent.GetComponent () == null) ? true : false; + trans.SetParent (parent, worldPositionStays); + } trans.localPosition = position; trans.localRotation = rotation; return obj;