Retaining UI element contents when changing scenes

Hi there, I have a game in which, when a user clicks a button, an on screen text UI object increases by one. There is also a button that changes the scene. If a user changes the UI text element to a number of their choosing, and the scene is changed to scene 1, and then changed back again to scene 0 (The scene containing the text object), the value in the text object resets to zero. Is there any way to retain the value of the text element even when changing scenes.

I have tried using the following code, but to no avail:

void Awake(){ DontDestroyOnLoad(this.gameObject); }

I have applied this script to both the canvas and the text element as other threads have recommended, but this hasn’t seemed to have worked.

Am I implementing this incorrectly, or is this the wrong way of solving the problem?


Could you potentially teleport the camera to another part of the scene instead of changing scenes?