I have an in-game phone and need it to change between screens, so I made a property that enables the given screen and disable others:
[SerializeField]
private AppScreen InitialScreen;
private AppScreen activeScreen;
public AppScreen ActiveScreen
{
get => activeScreen;
set
{
activeScreen = value;
activeScreen.transform.SetAsLastSibling();
foreach (Transform screen in transform)
{
Debug.Log($"({screen.name} == {activeScreen.name}) = {screen == activeScreen}");
screen.gameObject.SetActive(screen == activeScreen);
}
}
}
void Start()
{
ActiveScreen = InitialScreen;
}
The class has an Initial screen that is activated in the Start() method. This screen and another are the only children of this class.
That foreach is used to iterate over all screens and disable the screen if it isn’t the active one.
But instead it deactivates both screens, so I made a debug, and it looks kinda funny:
My question is: Why this happens and how could I fix that? Thanks