I have 2 different scripts. When the player’s leaves a room, the camera pans over to the next room. A timer float variable is used in the calculations for the panning of the camera. The timer is in a FixedUpdate method. I have another FixedUpdate method on an enemy’s script. When the player leaves the room the enemy is in, the enemy is destroyed. I was going to use the timer to destroy the enemy after the camera finished panning. The timer is a public static float and when set in the enemy’s FixedUpdate method, is not the correct value. It appears to be the last value the timer was set to. I don’t understand how Unity’s sequence of events works within FixedUpdates or methods that have the same priorities.
When I call a variable from another script, the value is from the last FixedUpdate, and not the current one. How would I fix this?
Unity uses a Script Execution Order when dealing with events of the same priorities. I see two solutions for your problem. You can set execution order of your script to be always called last or you can create an event at the end of your camera movement. This way when your camera finishes you will just invoke the event and destroy the enemy.
You could also play around with coroutines, but I would need to see your code in order to suggest some solution.