I am sorry if this has already been answered, but I was wondering why do we have :
GameSession gameSession;
scoreText.text = gameSession.GetScore().ToString();
in ScoreDisplay script, but in Enemy script we use
FindObjectOfType().AddToScore(scoreValue);
Without assigning it to a variable as in both cases we are working with data that is returned from GameSession?
I am sorry if this seems like a stupid question and thanks in advance for the answer.
At some point, we have to assign something to gameSession because the variable is null by default. We would get a NullReferenceException when we try to access something in the non-existing object. We can look for a GameSession object via the FindObjectOfType method.
But why do we even create gameSession as a variable? I mean in Enemy script we do not create it as a variable. My best guess is that in ScoreDisplay we take data and in Enemy we provide data, is that the reason? Also thank you for the link with the code formatting.