Create a countdown and start the timer
//Create and start a count down of 5 seconds.
Timer myTimer = Timer.Create(5f);
read the value as a normal progression of the countdown ranging from 0 to 1
//Interpolate between pointA and pointB by myTimer's progression to 5 seconds.
Vector2.Lerp(pointA, pointB, myTimer)
or as a bool
//While myTimer hasn't reached 5 seconds.
while(!myTimer)
Lightweight generic pooling class.
Pool is just a simple lightweight pooling system which takes care of the pooling boilerplate.
Pool<Slime> slimePool = new Pool<Slime>(
CreateNew: () => new GameObject().AddComponent<Slime>(),
OnChange: (isSpawning, slime) => slime.gameObject.SetActive(isSpawning));
The first parameter called CreateNew
is a Func<T>
which will be used
by the Pool class to create new instances of T
.
//Method which instantiates a gameObject, adds a slime component and returns a reference to it.
CreateNew: () => new GameObject().AddComponent<Slime>()
The second parameter is optional, called OnChange
which is an Action<bool, T>
and runs when a T instance is being either borrowed or returned.
//Enable or disable the slime component based on if it's being borrowed or returned.
OnChange: (isSpawning, slime) => slime.gameObject.SetActive(isSpawning)
Now that you've made a pool you can start borrowing and returning slime instances using slimePool.Borrow()
and slimePool.Return(Slime)
respectively.