The script I wrote below checks the state of a static variable “selectedObject” from another class, every time I want to access or change things inside this static variable, I have to check the if it is null to make sure the null error does not pop out.
I have written most of my scripts in this method and thought maybe there could be a better design for this. Any pointers or advice is much appreciated!
if(myScript.selectedObject != null && (myScript.instance.notDead || Interface.selectedObject.fainted))
{
myScript.selectedObject.CheckState();
}
if(powerScript != null && powerScript.addPower < 0f)
{
powerScript.addPower = 10f;
}
if(myScript.selectedObject != null && myScript.selectedObject.activates)
{
Destroy(myScript.selectedObject.activates.gameObject);
myScript.selectedObject.activates = null;
}