Hi MxHabit,
Maybe it will help to distinguish between the visual part and the code part. To display a string, you need a Text or TMP object. To change the value of the text
property during runtime, you need code. Since the text
property does not need a specific position within the game scene to be able to receive data, you could place your score display whereever you want.
When a new scene gets loaded, all game objects in the old scene get destroyed, except when Don’tDestroyOnLoad got called on them. If you call that method on “Game Session”, all its children will persist.
Don’t make the score display part of the Game Session object. There are different ways how you could make your score persistent anyway and to display the score in your game.
One way is to create a pure C# class with an actual singleton (first version). That pure C# class does not inherit from MonoBehaviour. It just stores an integer and returns it similar to what we did with our State objects in the AdventureGame class.
Then you need a “normal” component meaning a class inheriting from MonoBehaviour. That class/object calls a method in the aforementioned C# object and receives the score value, which it assignes to the text
property of the Text or TMP component.
This might sound a bit complicated but it is relatively easy to implement with your current knowledge. If you use Debug.Logs in the class inheriting from MonoBehaviour, you’ll very likely be able to figure everything out yourself.
If you get stuck, feel free to share your results here and ask for help.