Save Info to new scene
Reply on sbox.game-
I am trying to save the player score into a new scene, my score system works fine you collect items you gain points, but when I load the next scene/level it resets to 0, I'm not sure how to go about carrying this info over from scene to scene.... I tried making a game manager script, but that just resets with the new scene load as well.
Any help would be appreciated!! -
I figured it out,
I made a c# public class called ScoreManager:using Sandbox; public static class ScoreManager { public static int CurrentScore { get; set; } }Then on my player controller I do this:protected override void OnUpdate() { points = ScoreManager.CurrentScore; }And I add and subtract my points to the ScoreManager rather than directly to the players points:public void Addpoints( int Amount ) { ScoreManager.CurrentScore += Amount; }edited:The Score Manager just lives in your CODE folder or wherever you keep your scripts, no need to add it to your scene. -
just save it to a component and then set that components gameobject flag to DontDestroyOnLoad
https://sbox.game/api/Sandbox.GameObject/Flags