So lets say I have three variables.
var distanceright : float = 0.0;
var distanceright2 : float = 0.0;
var distanceright3 : float = 0.0;
would that be faster in the long run or making a.
var distanceright : float;
function start () {values = new float[3];}
I can’t speak for JS in Unity because I’ve never used it, but in C# there isn’t much difference, if at all in performance. I would recommend doing what looks cleanest and the least cluttered while maintaining meaning; If the variables are the same type and store the same logical item, then use an array. It will allow you to use loops and write less code later. Once you finish your game or reach some goal along its timeline, then you do performance testing to try and optimize what is running slowest. Don’t sweat the small stuff like this.
When I write code, 3+ is usually my cutoff point at which I always use arrays, and even then, I only use them if they are the same type, and store related “things.”
For example, if I have variables for something that is only temporarily used I might do
int numPrevFrame;
int numCurFrame;
If however, I needed to store an indefinite number of frames, I would use
int[] numOnFrames;
where in this example, the size can be defined at runtime, and an index of 0 would be the current frame, 1 would be the previous frame, and so on.