unity3d - Unity C# Passing Data Between Scenes -


this question has answer here:

i working on in-app purchase store game found on different scene. trouble having when click button example new skin white skin, in scene save data bool of "didwhiteskin" becomes true although when load gamescene wont save data therefore not run whats inside if statement.thank yall , answer questions if needed.

additional info: function chosewhiteskin() called when button clicked on storeview.

heres code:

using system.collections; using system.collections.generic; using unityengine; using unityengine.scenemanagement;  public class storescript : monobehaviour {      bool didwhiteskin = false;      public static storescript instance {         get;         set;     }      void awake () {         dontdestroyonload (transform.gameobject);         instance = this;     }      // use initialization     void start () {         scene currentscene = scenemanager.getactivescene ();         string scenename = currentscene.name;          if (scenename == "gamescene") {             if (didwhiteskin) {                 debug.log ("this ran");                 //this put function change skin issue if statement never being ran             }         }         else if (scenename == "storeview") {          }     }      // update called once per frame     void update () {      }      public void chosewhiteskin() {         playerprefs.save();         didwhiteskin = true;     } } 

you can define global variable scenes this:

public static int didwhiteskin = 0; 

so can declare , initialise variable in first scene in game, , refer in other scene may create.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -