Let me explain. I have 5 scripts for 5 enemies, and they all have the variable “activatedFlag” to determine when they are active and can move. These variable are declared as such:
object class
{
public bool activatedFlag = true;
start
{
if (activatedFlag == true)
{
do stuff;
}
}
}
The variable is only changed by another script, the Game Controller. It activates and deactivates enemies. Normally its set to false.
Now I already had this working with my enemies, but I was making a new enemy and was writing it from scratch and for debugging purposes had it set to true and to public. The problem was that it wasn’t working. In the inspector, it stays false even though it’s set to true. As soon as I changed the variable to private, it began to work.
Normally, my other scripts work. They’re public and set to false, and so long as my Game Controller script changes the variables in every enemy instance on and off, they’re good. But I’m not able to get them to work if I set the individual instance to true.
Why is this?
I declare and initialize the variables in the class space, not in any function. They’re also not static so they shouldn’t be causing problems outside of the class.
Am I not able to have public variables of the same name in different scripts?