In the course, the score text is updated every frame. This seems ineffective because the score will only need to be updated after the method AddToScore in GameSession.cs is called and at the start of each scene. I know that this is a relatively small game and therefore the performance won’t be too heavily impacted but it still seems like a waste of computer processing power.
When I originally attempted the challenge before seeing the rest of the video I attempted to solve this issue. I had a reference in my GameSession to my ScoreDysplay component on the Score Text object and cached the reference during Start. I had a function in my ScoreDisplay.cs that updated the text and I would call this at the beginning of when Awake and AddToScore were called. This didn’t update the text when I switched from one scene to another, because the Score Text object would change and my reference would become invalid, but with IntelliSense, I found the function OnLevelWasLoaded and by re-caching the reference to the text I was able to get it to work.
While my solution does work, it also damaged the readability of my code and it feels like there should be a better way to do this. So my question is, how could I get a reference to the score text every time a scene loads and when GameSession is not destroyed on load, or is there a completely different way to avoid setting the text every frame that I completely missed?