How to compare two different variables in two different scripts?
Hi! I would like to compare variables in two different scripts so when the two variable is not equal an if statement does something while if they are equal it does nothing.
I tried to reference and compare them in multiple ways but it either doesn't work or I get null reference exceptions or one sided results. Couldn't find out why is it giving null reference exceptions, I tried to reference GameObjects with the scripts attached to them but couldn't get the results I wanted.
What should happen : when the player goes trough a Gate with the same color as the PlayerColor nothing happens. But when their color differs it should lead to a game over.
I have an Appinitialize script which contains a change color button method so when a button is pushed the player object changes color. It is attached to an empty GameObject called SceneManager. The GateObject has a GateColor script which defines a gates color on start.
I've tried to create a public variable in the GateColor script and store the current color of the gate and then created another variable in the Appinitialize script which is changing when the button is pushed. I tried to compare them by a similar code:
if (currentColor != currentGateColor)
{
GetComponent().GameOver()
}
I tried to use Debug.Log() to see if the variables are changing and are the same but even if they are I and I get no error in Unity or inside the compiler, I still don't get the correct results.