This is a weird problem I started to have today. I have a member variable that I set when a public function is called by an external script. But on the next cycle the Update() function this variable is not updated. Next time the public function is called the variable has the new value.
It seems almost like there are two instances of the same class. One that is called by the external script and one that is updated every frame. Did you guys ever seen anything like this? Any suggestions on how to solve the issue?
Here is piece of my code for you to check:
public void StartFlashing(float flashDuration) {
lightState = LightState.LIGHT_FLASHING;
}
// Update is called once per frame
void Update () {
if (lightState == LightState.LIGHT_OFF) {
return;
}
//Code never get to this point.
...
}
LightState lightState = LightState.LIGHT_OFF;
The function that calls StartFlashing is another script in the same game object. I tried to use both getcomponent<>() and also exposing a script reference to the editor. Both gives the same result.
What do you guys think?