in order of worst to least. Overlapshpere, raycastall, raycast, and vector3 distance. are all mistakes i made to forse the rewrite of my last project not on your list. they are wonderfull tools but must be limited depending on your project.
something as simple as :
var frame:int;
frame=frame-1;
if (frame ==0){frame=10;
//---now check a heavy sherecast your game needs
}
can lighten the load on your cpu greatly
it all depends on what you are doing. one thing i found is that the friendly game engine developers with unity created colliers that DO NOT slow game progress. i have tested thousands in a level.
any type of “Find” or “lookup” should never be called more than once! anything more should be stored in a variable or array for fast lookup.
“destroy” should be avoided. things like bullets are recycled…not destroyed.this also reduces the need for instaniate. even though unity does it automatically, there is a term called garbage collection. where a system goes through a laggy proccess of freeing ram memory for things “destroyed”. its better to move bullets under terrain untill recycling or make them invisible when not in use.
debug and print definally slow a game…when code blocks are desireable delete for final builds.
i havent seen evedence of asking"position" or rotation slowing things but if you where worried you could also pack a common request in the top of your update.
i do that just for easier typing somtimes in a longer code.
var tp:Vector3;
function Update(){
tp=transform.position;
if (tp==this){do this;}
if (tp==that){do that;}
}
everyone complains about the gui system being slow.
if you want to pick up on a mouse click on a position. why not put it in your update???
function Update(){
sw=Screen.width;
sh=Screen.height;
mx=Input.mousePosition.x;
my=sh-Input.mousePosition.y;
if(Input.GetMouseButtonDown(0)){
if(mx>sw*.2){if(mx<sw*.3){
if(my>sw*.2){if(my<sw*.3){
//i know you clicked a spot on the screen without a giu button
}}}}}
remember that all unitys funtions are basically something in your script that you dont see. depending on the function, unity could run hundreds of lines of code, potentially on hundreds of different objects in a scene on the frame you call some of these options. then your game waits for a return from unitys scripts/functions.
for large games accomplishing big things professional developers use several technics that are specialized for the problem in your game. such as as only checking a distance for things within a specific camera distance or packing references into super fast arrays or lists for lookup. if you could give us details about your game and what you think might be slowing it, we can give you some ideas on how to get around it!!!