I am still new to unity and recently I want to build a timer attached to a slideshow for further design. But I found out that somehow the time of the timer always fall behind the time of the slideshow changing about 2.5 seconds. Any help will be appreciated.
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
using UnityEngine.UI;
public class exp : UdonSharpBehaviour
{
public Sprite[] spriteList = new Sprite[10];
public SpriteRenderer spriteRenderer;
public float[] times = new float[10];
[HideInInspector]
public float[] y;
public Renderer rend;
public Collider sphere;
[HideInInspector]
public int page = 0;
public Text display;
private float time = 0f;
public bool playing = false;
private bool timerplaying = false;
public override void Interact() //button interact//
{
time = 0f;
playing = true;
page = 0;
rend = GetComponent<Renderer>();
sphere = GetComponent<Collider>();
rend.enabled = false;
sphere.enabled = false;
y = times;
timerplaying = true;
}
private void FixedUpdate() //slideshow move + timer move//
{
if (!playing) return;
if (!timerplaying) return;
time += Time.deltaTime;
if (y[page] > 0f)
{
y[page] -= Time.deltaTime;
display.text = "Timer: " + y[page].ToString("F1");
}
else
{
page++;
}
if (playing == true && time > times[page] && page < spriteList.Length)
{
page++;
spriteRenderer.sprite = spriteList[page];
time = 0f;
}
}
}