Visual debugging in Scene View with Handles.label

Sometimes we need to see info about objects during playtime for debugging.

Lets say, we’re making a destructible environment and we need to debug the health of objects in the scene.

OnDrawGizmos() is a Unity callback, like Update() and FixedUpdate(), but only for the editor’s scene view. It isn’t called all the time, like update or fixedUpdate, but only when something “changes” in the scene.

And the Handles class is the API for those arrow things that lets us do scaling, positioning and all that jazz in the scene view. We can define our own version of these but for the sake of debugging, we can use the .Label() function to print some info on our object.

And just like that, we have visual debug info in the scene.

Coroutines can wait for other coroutines

Coroutines let us go from just writing functions to creating complex sequences with delays and timings.

(Note: If you haven’t used coroutines before, here’s a video that nails it.)

The most immediate uses for coroutines are for things like timers and animation sequences.

Stuff like “Count to 3 and explode”.

And this is great. A coroutine is perfect here.

But we can take this further.

What if we wanted a loading sequence which did something like:

“Show the loading screen, prepare the next level and, when it’s ready, hide the loading screen.”

In this example, the loading screen will show and 2 seconds later, when the level is done loading, hide itself.

The magic here is that a coroutine can  yield return  another coroutine, which resumes the original function when it’s done. Well worth keeping in your programming toolbelt!

Word of caution: nesting 3+  yield return ‘s that wait for coroutines to finish can be a pain to skim through and understand, so use it only when it makes sense!