Unity create local variable for Time.DeltaTime for math calculations

I recently thought about how to code in a better way. Currently, I'm doing math calculations and wondering if I should cache "Time.deltaTime" into an own variable for sake of synchronization.

float a = speed * Time.deltaTime;
float b = speed / Time.deltaTime;
float c = a - b;

Or

float deltaTime = Time.deltaTime;
float a = speed * deltaTime;
float b = speed / deltaTime;
float c = a - b;

This is just random code I made up, but the point is when calling "Time.deltaTime" is calling internal update.

    //
    // Summary:
    //     The interval in seconds from the last frame to the current one (Read Only).
    public static float deltaTime
    {
        [MethodImpl(MethodImplOptions.InternalCall)]
        get;
    }

Meaning not in sync, right? Obviously this is a minor thing, but still should you cache "Time.deltaTime" for staying in sync?



from Recent Questions - Stack Overflow https://ift.tt/3oqzm4t
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)