A method running each millisecond in real time
Hello. I'm new in Unity. I'm making a game with haptic devices. I need a method running as maximum each millisecond, because I need read 200 data each millisecond. I have tried with coroutines, InvokeRepeating, and threads, but these aren't accurate. Thanks in advance.
What does "unless each millisecond" mean? Also, can you give a code example of what you tried? Specifically with the coroutines.
Okay a couple of things I don't understand what you're asking and it seems like someone else didn't either so possibly rephrase the question? If this helps you,
The update function does NOT go by milliseconds, it runs every frame. It says then when you first load a script up, and if you didn't know, a frame is 1/30th of a second. So it is quick.
If you have A coroutine it only runs once, maybe at the end of a coroutine you start it again making it loop? At least that's what I do.
If these don't answer your question(s) please rephrase, thanks !
Happy coding and good luck in unity (:
A frame is not 1/30th of a second... it's as many as the computer can handle. Basically less scripts and tris = more frames/second. 30fps is just a number people like to have as a $$anonymous$$imum, people tend to prefer 30 or higher.
Ok. I have tried corotutines with InvokeRepeating. but these aren't accurate for my purposes, it doesn't respect the time in few words. I used coroutine with while loop, but this is freezing the entire software. I modified update with Application.framerate together with QualitySettings.vysync in 0 but this give me 0.006 seconds. And thank you for the desires.
There is no feasible way you will get Update () to run 200 time in a single milisecond. I don't know if an single if statement could run that fast on most computers. There is no game ever imaginable that you'd need "200 data per millisecond". and if you think otherwise, you're doing something wrong.
Anyways an answer to this question is to use a looping Coroutine with a WaitForSeconds(.005), and a computer that costs around $100,000. It's possible sure, it's just not feasible, so find another way around.