Sorry, I haven't looked at that code in ages ... not sure why, the web version doesn't crash but I've moved on from Unity.
Which framework or game engine are you currently working with?
Godot