I have set up the notification center in my game and I am trying to use it to send health information to two different health bars. The type of information is exactly the same (currentHealth and maxHealth) but I would like to use one function to handle displaying the information. So, if the player health bar (a GUI texture) is on the left it should show the player health and a similar texture on the right will show the selected mob’s health. I just want the message about the health to go to the right place, if that makes sense.
Also, for some reason it is not cleaning up all its default notification centers and always leaves one or two behind, how can I fix this?
So this answer is very late, but its intended for folks googling this as i did.
Notification center attempts to spawn another instance of it self due to postNotificaiton being called after the application has begin quitting, and the original notification center has been destroyed.
You need to add a check to notification center telling it to not create another instance if the application is closing like so:
private static bool ApplicationShuttingDown = false;
private static NotificationCenter defaultCenter;
public static NotificationCenter DefaultCenter
{
get
{
if (!defaultCenter !ApplicationShuttingDown)
{
GameObject notificationObject = new GameObject("Default Notification Center");
defaultCenter = notificationObject.AddComponent<NotificationCenter>();
}
return defaultCenter;
}
}
//Do not spawn notification centers if the application is quitting.
void OnApplicationQuit()
{
ApplicationShuttingDown = true;
}