- Home /
Resources bar in every scene
Hi. I have small problem in the beginning of my game making. My game have main scene, where you can get to every other scenes in the game (the game is a rpg clicker like "Game of Sultans") . And my problem is that I want to have resources bar (with gold, diamonds, soldiers) in every scene on top of the screen. In other words, when I go from main scene to other scene I will have the same resources bar in that scene (with the same values). Can you help me to do that?
Answer by Cornelis-de-Jager · Mar 01, 2019 at 05:44 AM
Create the Resource bar in the MainMenu screen and add a script to it with:
void Awake () {
DontDestroyOnLoad(gameobject);
}
Then simply hide it in your main screen, but show it in your other scenes. It will stay when switching scenes.
Answer by bankastudios · Mar 01, 2019 at 09:16 AM
I tested it on two scenes and on the first one (main scene) it is not visable, on second one it is but when i go back to main scene it disappears again.
You need to put the bar in the first scene(main) only. Use the script. And then you will see it in Don't Destroy on Load Hierarchy
Try marking it as static and double check if it you've used awake and script is in the object along with having object ONLY on the main scene. Is the don't destroy on load visible during play mode
Okey I fixed it. $$anonymous$$y resources bar was in a canvas so I needed to make another one, put the bar in there and attach script with dontdestroy to that new canvas. But now i have another problem. When I load New scene and my resources bar show up its ok, but when i go back to main scene I have two bars then