I am very interested in knowing how much of a difference it makes performance-wise to put the code in the update-function, versus changing the variables outside of the update-function.
Take this code for example:
void Update()
{
transform.position = otherObjectsScript.transform.position//Moves the object to another object
if (x == 10)//If x becomes 10 it is reset.
{
x = 0;
}
}
All of the code above could be moved to other functions in the script, because the position only has to be updated occasionally when the player clicks. If the player has not done anything, the transform.position-line will simply set the object’s position to the position that it is already at, so updating it at this time changes nothing.
Also, the variable x will only change during certain player actions, so the check that resets x could be done only in these circumstances instead of the update-function.
So, the question is: Would it significantly (in the long run) improve the preformance of the game to make these kinds changes outside of Update() as described above, or does Unity make this more or less the same (by detecting that the variables have not been changed, and thus not process the lines)?