Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Resolved Save Game data through scenes

Discussion in 'Scripting' started by othmaniislem1, Aug 2, 2020.

  1. othmaniislem1

    othmaniislem1

    Joined:
    Jun 22, 2020
    Posts:
    10
    Hey guys, i'm currently making a 2d game. I made a menu scene and a game scene. In the menu scene i have a button named background that takes you to another scenes where there is a bunch of backgrounds and you choose which one you want in your game. When i choose a background and then go to the game scene it doesn't change at first when i lose and press restart it changes. Is there a way to fix this so it can change when the game starts? Please i need help
     
    Last edited: Aug 2, 2020
  2. adehm

    adehm

    Joined:
    May 3, 2017
    Posts:
    85
    When changing scene it will appear the way you left it when designing the application. Easy way to store the value representative to the user selection would to make a static script with a static variable and then on Start() of the scene change the background dependent on that variable.

    Code (CSharp):
    1.  
    2. public static class GlobalValues
    3. {
    4.     public static int BackgroundSelection = 0;
    5. }
    6. void Start()
    7. {
    8.     switch(BackgroundSelection)
    9.       {
    10.           case 0:
    11.           //insert background change -- GlobalValues.BackgroundSelection
    12.           break;
    13.       }
    14. }
     
  3. othmaniislem1

    othmaniislem1

    Joined:
    Jun 22, 2020
    Posts:
    10
    Thanks my guy but i already fixed it with player prefs
     
unityunity