Another area prone to performance problems and ripe for optimization is your C# script code. Throughout this book, we have used various coding best practices, without always explaining why. (On the other hand, some examples in this book are not necessarily efficient, in favor of simplicity and explanation). InChapter 9,Playing with Physics and Fire, for example, we implemented an object pool memory manager to avoid repeatedly instantiating and destroying game objects that cause memorygarbage collection(GC) issues, which, in turn, slows down your app.
In general, try to avoid code that repeats a lot of computation over and over. Try to pre-compute as much work as you can and store the partial results in variables. At some point, you may have to use a profiling tool to see how your code is performing under the hood. If the Profiler indicates that a large amount of time is spent in the scripts that you've written, you should consider another way...