-
-
Save peroon/2f4837faba50a6e32b13 to your computer and use it in GitHub Desktop.
Object Pooling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Object pool. | |
Queue<GameObject> objectPool; | |
objectPool = new Queue<GameObject>(); | |
.. | |
// Reuse the oldest object in the pool. | |
var go = objectPool.Dequeue(); | |
go.SetActive(false); | |
go.transform.position = position; | |
if (rotationMode != RotationMode.Keep) | |
go.transform.rotation = rotation; | |
go.SetActive(true); | |
objectPool.Enqueue(go); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment