1.
Using Unityengine;
Class Garbagecollectmanager:monobehaviour {
public int framefreq = 30;
void Update () {
if (time.framecount% Framefreq = = 0)
System.GC.Collect ();
}
2.
using Strict
using #pragma at the top of all your scripts, the script will be strongly typed, avoiding the wrong type assignment when writing code.
avoid object.instantiate () and Object.destroy ()
instantiating and destroying are not good, because they need to dynamically allocate memory when creating and destroying objects, which can temporarily affect performance.
the alternative to consider is to use the Spawnmanager class he wrote. It initializes all of the objects at the beginning of the game, so that you can load objects together when the game is loaded, so that people don't feel the impact.
When you disable objects, they remain in memory and only need to be enabled when they are needed.
There are a few other points that each
Cache Component Lookups
use iTween sparingly less
Avoid setactiverecursively ()
Use Builtin Arrays
Avoid String Comparison strings comparison
Avoid Vector3.magnitude & Vector3.distance ()
ability to see specific instructions at the source of the reference