- Home /
Keep moving when window is minimized
This is my little code:
rigidbody.transform.position += rigidbody.transform.right * speed * Time.deltaTime;
So this will move the transform forward, constantly, but when I minimize the screen, or even close it, it will stop moving, I want to know how to make it so it keeps moving forward even when the window is minimized or closed (closed because this is multiplayer).
Thanks in advance.
Matijs
Answer by Sildaekar · Mar 10, 2014 at 07:13 PM
I'm not sure how to make it keep moving when the window is minimized, but this is NOT possible to do via client side when the window is closed. When a program is closed the stack is erased and all objects are removed from memory.
Your best bet would be to create an Authoritive Server (where the server controls everything and the client just tells it what's going on with them). Then on the server you could have objects continuing to move.
Check out these links:
http://forum.unity3d.com/threads/112430-Authoritative-server-example-demo
http://playblack.net/zee-code/unity-3d-authoritative-server-networking-pt1
http://forum.unity3d.com/threads/199538-Tips-for-server-authoritative-player-movement
Thanks alot, i'll check this out if there is no other way, cause I dont want everything to be server side. Is there a way to see like: If window is closed then... ?
Here are a few other topics I found that should point you in the right direction to detect if the application is being closed:
http://answers.unity3d.com/questions/54674/is-there-a-way-to-know-when-the-application-is-in.html
http://answers.unity3d.com/questions/224215/how-to-detect-in-ondestroy-if-scene-is-closinggame.html
http://answers.unity3d.com/questions/167984/call-a-function-when-app-exits.html
If this answers your questions please don't forget to mark this answer :)