Skip to content

Commit d9dd944

Browse files
committed
addendum to previous commits
1 parent 1e4498f commit d9dd944

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

Assets/CustomTools/ObjectPooling/Scripts/ObjectPooler.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,22 @@ public GameObject SpawnFromPool(PooledObjectType pooledObjectType, Vector3 posit
5959
{
6060
objToSpawn = _poolDictionary[pooledObjectType].Peek();
6161
objToSpawn.SetActive(true);
62-
objToSpawn.transform.position = position;
63-
objToSpawn.transform.rotation = rotation;
62+
63+
if (parent)
64+
{
65+
objToSpawn.transform.SetParent(parent);
66+
}
67+
68+
RectTransform rect = objToSpawn.GetComponent<RectTransform>();
69+
if (rect != null)
70+
{
71+
rect.anchoredPosition = position;
72+
}
73+
else
74+
{
75+
objToSpawn.transform.position = position;
76+
objToSpawn.transform.rotation = rotation;
77+
}
6478

6579
IPooledObject iPooledObj = objToSpawn.GetComponent<IPooledObject>();
6680

@@ -81,17 +95,6 @@ public GameObject SpawnFromPool(PooledObjectType pooledObjectType, Vector3 posit
8195
return ExpandAndSpawnFromPool(pooledObjectType, position, rotation, parent);
8296
}
8397

84-
if (parent)
85-
{
86-
objToSpawn.transform.SetParent(parent);
87-
}
88-
89-
RectTransform rect = objToSpawn.GetComponent<RectTransform>();
90-
if (rect != null)
91-
{
92-
rect.anchoredPosition = Vector2.zero;
93-
}
94-
9598

9699
return objToSpawn;
97100
}

0 commit comments

Comments
 (0)