- Home /
different Time.deltatime speed when playing the game build
Hello there! I'm having a little trouble using the Time.deltaTime function.
I am making a rhythm game in unity, and I made a script for delivering notes to the player. So I've used the Time.deltaTime function in the transform.Translate line, but it doesn't seem to work as it should.
In the unity build, the cubes move slightly faster than in the unity test
Here's my script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseCubeClick : MonoBehaviour
{
public AudioSource ClickSound;
public Vector3 Cube;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
private void OnMouseOver()
{
if (Input.GetMouseButtonDown(0) || Input.GetButtonDown("ClickNotesButtons"))
{
Destroy(this.gameObject);
ClickSound.Play();
}
}
private void FixedUpdate()
{
transform.Translate(Cube * Time.deltaTime);
}
}
I would really appreciate it if anyone could help!
Thank you!
Don't know why but something is telling me it needs to be in Update not FixedUpdate.
Update @HoweToGa$$anonymous$$g :
Your suggestion, sadly, has not worked :(
You definitely have a problem in your original script, which is that you are using Time.deltaTime inside of FixedUpdate instead of update. Time.deltaTime is just the time in seconds since the last Update cycle ran, but FixedUpdate does not run at the same rate as Update.
The solution is either to use Time.fixedDeltaTime instead, or to keep Time.deltaTime and move over to Update. It is weird that this didn't work for you though. I suggest trying again or trying Time.fixedDeltaTime.
Answer by SentokaioStudios · Mar 03, 2021 at 11:32 PM
Basically, the notes are being delivered earlier in the Unity Build, and not in sync with the music, like the Unity test
I played the videos side by side and it looks to me like the cubes are moving at the same speed. I can't hear the audio so I don't know how far it's off, but could it just be an audio syncing issue between the cubes spawning and the music? How do you currently sync the two?
I sync them manually, I put the audio in a separated GammeObject, and I create the cubes separately. You might not hear the audio but trust me, it's out of sync @unity_ek98vnTRplGj8Q
So when you say you sync them manually, you mean you say "Ok at 10 seconds I am going to spawn this cube and at 10.5 seconds I am going to spawn this cube"? If so, how are you guaranteeing that the start of the cube spawner timer corresponds with the start of the audio playing? Could that be the issue?