Memorize WaitForSeconds- C# Skill in Unity: 1

S.J. Jason Liu
2 min readSep 22, 2021

Quick tip: store WaitForSeconds to treat your script better.

When using coroutine in script, especially with loop, we usually call it after a keyword “new”, like new WaitForSeconds(). In fact, you can make it easier to process this script without creating a new class every specific time.

Reference of WaitForSeconds()

To make it easier, you can get the reference of WaitForSeconds() to release more memory usage on a script.

Then assign it to a new WaitForSeconds.

Usage in coroutine

When calling a coroutine, you can use the created reference instead of setting a new class to repeat that coroutine.

Imagine that this script would repeat from the very beginning of your game and till the end of it, it would save lots of memory with this way, instead of calling the coroutine every fixed time with the waste of memory.
It should be helpful when developing a big project.

--

--

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.