0

I've been going around for a few days with a topic about local variables and the Unity update function, (I mean before I'm new to Unity and C#).

As I understand the local variables are usually faster than declaring them global (I do not mess up).

Taking this example code I saw in a question, and applying my question:

void Update () {
        ..//
        Vector3 to = new Vector3 (0, 0, -85);

My question is in C#, local variables comply with what is faster than global?

And the other doubt, it is from the point of view of preform, how efficient it is to create variables in the update Vector3 to versus make them global.

I hope you understand my question. I am sorry for my bad english.

Angel Angel
  • 19,670
  • 29
  • 79
  • 105
  • 1
    local variable will be created every time `Update` gets called and it gets called 30 times a second so... But it mostly depends on what this variable is suppose to do really. If it doesn't change make it const and global, I guess it's not a good practice to create anything in `Update`, but you should look at the profiler and get more information there. There's also the compiler that optimizes your code. – FCin Jan 14 '17 at 20:23
  • 1
    It depends on the type. Looks like a duplicate of [this](http://stackoverflow.com/questions/40253168/is-there-a-point-in-recycling-value-types-unity/40263263#40263263). Please read. – Programmer Jan 14 '17 at 21:31

0 Answers0