Hello. I am making a sprite fade with given time, and it works correctly, but should i use Time.deltaTime in this example so the fading effect could flow with the same speed in every computer? How to use it in this example?
void OnTriggerStay(Collider other)
{
if (!isFadedAway)
{
if (other.gameObject.name == "Player")
{
if (!startTimeGiven)
{
startTime = Time.time; //SHOULD I USE DELTATIME IN HERE?
startTimeGiven = true;
}
t = (Time.time - startTime) / duration; // OR HERE
sprite.color = new Color(1f, 1f, 1f, Mathf.SmoothStep(maximum, minimum, t));
}
}
}
Time.time is the actual game time. For example if the game is running and you started the game 20s ago, Time.time will return 20s. Time.deltaTime is the time that there’s between two calls of Update(). Update() calls depend on the performance of your computer. For example if there are 200 calls of Update() in one second, Time.deltaTime would return about 1/200. (Careful that this value isn’t always the same, timing calculations aren’t always the same). On a slower computer you wouldn’t have 200 calls in 1 second, maybe 150 so Time.deltaTime would return about 1/150. Time.deltaTime doesn’t have always the same value, there can be like 0,01s between 2 frames but the next frame can be 0,5s, it depends what’s happening in your game. In your code it seems that you want to get the time so Time.time is fine to use. You can also get the same result using Time.deltaTime