HaiiroMukuro wrote:Good day!
How to create a persistence data script for variables?
The variables are:
Money as int
Mathematics as bool
Achievement as bool.
You can either start with a copy of
PersistentDataTemplate.cs or just add OnRecordPersistentData() and OnApplyPersistentData() methods to your existing script. For example:
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class MyScript : MonoBehaviour {
public int Money;
public bool Mathematics;
public bool Achievement;
void OnRecordPersistentData() {
// Before saving game, record variables into Dialogue System's Lua environment:
DialogueLua.SetVariable("Money", Money);
DialogueLua.SetVariable("Mathematics", Mathematics);
DialogueLua.SetVariable("Achievement", Achievement);
}
void OnApplyPersistentData() {
// After loading game, retrieve variable values from Lua:
Money = DialogueLua.GetVariable("Money").AsInt;
Mathematics = DialogueLua.GetVariable("Mathematics").AsBool;
Achievement = DialogueLua.GetVariable("Achievement").AsBool;
}
}
The PersistentDataTemplate.cs file has a lot of comments explaining how it works.
HaiiroMukuro wrote:Also for the feature demoscript.
I'm using the feature demo script because I'm trying to create my own prefab for the main menu. Now, it's working, but there's i wanted to try. Making the menu open by the button. My question is how to make the feature demo script to be open using the button?
Thanks for the help in advance.

Edit FeatureDemo.cs, and change line 70 from:
Code: Select all
private void SetMenuStatus(bool open) {
to:
Code: Select all
public void SetMenuStatus(bool open) {
Then point your button to call FeatureDemo.SetMenuStatus, and tick the checkbox.