Tracking progress on a map

Hi,

Very new to Unity but I’m currently building out a VR project. I’m getting the hang of things like gameobjects, environments etc… but struggling a bit with scripting.

What I have is a map scene with various popups that will appear as you progress through the ‘game’. Each popup has a button which you click and then are taken to another scene where you watch a video and then click a button to return to the map scene.

On returning to the map scene I want the next popup to appear. My thinking is bascally to have a variable called “mapprorgress” increase by 1 when the user clicks the previous popup, then on returning to the map another script will check the value and display the next popup based on the value.

Map Load First time - “mapprogress = 1”
Map Popup 1 click - “mapprogress +1”
Return to map - “if mapprogress = 2 then show popup2, elseif mapprogress =3 then show popup3 etc…”

Am I going about this the right way? It feels like there might be an easier way to accomplish this?

I would not write code like that, except perhaps if you only have two or three of them at maximum.

Instead, spend some of your character points in data structures and learn how to represent game state in ways that can be serialized and saved off to disk.

It could be as simple as an array of booleans, or even just using a single integer (such as your “mapprogress”) to look up an array of things to enable.

There are tons of “progress menus” and “progress level selection” tutorials on Youtube. Do two or three of them until you grasp all the parts that are in play making it work.

Finally, for actually storing the state between runs:

Load/Save steps:

https://discussions.unity.com/t/799896/4

An excellent discussion of loading/saving in Unity3D by Xarbrough:

https://discussions.unity.com/t/870022/6

Loading/Saving ScriptableObjects by a proxy identifier such as name:

https://discussions.unity.com/t/892140/8

When loading, you can never re-create a MonoBehaviour or ScriptableObject instance directly from JSON. The reason is they are hybrid C# and native engine objects, and when the JSON package calls new to make one, it cannot make the native engine portion of the object.

Instead you must first create the MonoBehaviour using AddComponent() on a GameObject instance, or use ScriptableObject.CreateInstance() to make your SO, then use the appropriate JSON “populate object” call to fill in its public fields.

If you want to use PlayerPrefs to save your game, it’s always better to use a JSON-based wrapper such as this one I forked from a fellow named Brett M Johnson on github:

https://gist.github.com/kurtdekker/7db0500da01c3eb2a7ac8040198ce7f6

Do not use the binary formatter/serializer: it is insecure, it cannot be made secure, and it makes debugging very difficult, plus it actually will NOT prevent people from modifying your save data on their computers.

https://docs.microsoft.com/en-us/dotnet/standard/serialization/binaryformatter-security-guide

Wow! That’s an amazingly helpful reply, thanks! I suspected I was probably approaching this the wrong way so that really helps. I’ll look into everything you’ve suggested. Thanks for taking the time to explain that all. Much appreciated