Hello everyone!
So, yesterday, I wrote a script. It was wonderful. It worked.
Then I accidentally deleted a few simple prefabs and once they were put back together again, the scripts did not quite work together the way they were supposed to, even though I am pretty sure I had not changed a single character. I’ll try to explain as best as I can what I was doing but I am a beginner, so please bear with my terrible use of programming terminology.
In my scene I have two identical text boxes on top of each other. When the “main” text box is inactive, then the second one can be activated under specific circumstances (clicking on tagged objects). However, after the little accident, the second text box remains stubbornly active throughout!
So basically, I have a C# Monobehaviour “parent” script as well as another script which inherits from it.
In the former, I have:
public class TextBoxManager : MonoBehaviour {
public GameObject textBox;
public bool isStoryTextBoxActive;
//...
void Update() {
if (textBox.activeInHierarchy == false) {
isStoryTextBoxActive = false;
} else if (textBox.activeInHierarchy == true) {
isStoryTextBoxActive = true;
}
}
}
With the textBox correctly assigned to a Panel to which is attached a Text UI. (It is actually one of the prefabs that I accidentally deleted.)
In the second script, I have:
public class ClickObjects : TextBoxManager {
void Update () {
if (isStoryTextBoxActive == true) {
textBox.SetActive(false);
// A note: I added this script after the problem manifested itself. Before that everything worked perfectly fine without it! I still left it in because it feels like added security, if you see what I mean.
}
if (isStoryTextBoxActive == false) {
//...
}
}
}
With the textBox assigned to the SECOND panel with its own text UI.
After inspecting every element with care while in Play Mode, it seemed that one of the boolean (“isStoryTextBoxActive”) does not seem to update from one script to another anymore. At the beginning of the game, the empty game object that holds the TextManager script does register that the story text box is active, however its child empty game object with the ClickObjects script does not!
Once again, everything worked fine before.
Any help would be greatly appreciated! Thank you very much for your attention.