Memorize WaitForSeconds- C# Skill in Unity: 1

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
S.J. Jason Liu

S.J. Jason Liu

99 Followers

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