What is the best choice? with
Time.deltaTime
I sometimes get some “timeskips” when adding the value to a variable, in the Update()
:
currentMS += Time.deltaTime * 1000;
The init value is 0 (int), but when adding the currentMS = Time.deltaTime * 1000
(milliseconds), it sometimes skips and adds a high number, it can best be descriped as similar to a frameskip or a fps drop. Can I use FixedUpdate()
with Time.fixedDeltaTime
instead?
The code is based on images (frames) extracted from a movie file. The frames are then inserted into an array. And the code switches frames based on fpms (frames per millisecond).
m = frames per millisecond
f = frames per second
m =(1/f)*1000
My current code is here:
using UnityEngine;
using System.Collections;
[System.Serializable]
public class SVideo : MonoBehaviour {
public Texture2D[] frames;
public bool isPlaying = false;
public int fps = 1;
private int ms = 1000;
private float currentMS = 0f;
private int i = 0;
// Use this for initialization
void Start () {
ms = (int) ((1f / (float) fps) * 1000f);
Debug.Log("FP-MS: " + ms);
}
// Update is called once per frame
void Update () {
if (isPlaying) {
currentMS += Time.deltaTime * 1000;
Debug.Log("Current MS: " + currentMS);
if (currentMS >= ms) {
currentMS = 0f;
if (i >= frames.Length-1) {
i = 0;
}
this.renderer.material.mainTexture =(Texture) frames*;*
-
i++;*
-
}*
-
}*
-
}*
-
void OnDrawGizmos() {*
-
Gizmos.DrawIcon(this.transform.position, "SVideo.png", true);*
-
}*
-
public void Play() {*
-
isPlaying = true;*
-
audio.Play();*
-
}*
}