Beginner Scripting: DeltaTime


I

n this weeks Coding Task it looked at the DeltaTime function. The term delta means the difference between two values. The DeltaTime is essentially the time between each update as the game is running. You can use this function to smooth out any movement happening within your game. The amount of time it takes to update a frame can vary and this can result in lagging. DeltaTime can give the change in seconds rather than in frames. This can help smoothen all movement when applied correctly.


The code is as follows


UsingDeltaTimes

using UnityEngine; using System.Collections; public class UsingDeltaTime : MonoBehaviour { public float speed = 8f; public float countdown = 3.0f; void Update () { countdown -= Time.deltaTime; if(countdown <= 0.0f) light.enabled = true; if(Input.GetKey(KeyCode.RightArrow)) transform.position += new Vector3(speed * Time.deltaTime, 0.0f, 0.0f); } }

Comments

Popular Posts