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.

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Setting up and Understanding Git for Unity!

Java Stream API

Maintaining peace in your serverless stack with Thundra Alerts!

Number of Active Users Right Now on Your Site

Deeppavlov @ GSoC: First Milestone passed

Industry Use Case on Automation Using Ansible

Documentation and Developer Onboarding

How Much Does It Cost to Develop a VR App?

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

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

More from Medium

Creating An Advanced 2D Player Controller Without Any Unity Components! (Part 1)

How to use Post Processing in Unity

Unity Dev: From Prototype to Work of Art

Making Tic Tac Toe Using Unity 2D and C#