Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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:
    11
    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:
    369
    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:
    11
    Thanks my guy but i already fixed it with player prefs