【发布时间】:2017-08-15 04:56:30
【问题描述】:
我目前正在为我的游戏开发一个应用内购买商店,该商店位于不同的场景中。我遇到的问题是,当我单击一个按钮时,例如针对白皮肤之类的新皮肤,在那个场景中,它会保存“didwhiteskin”的布尔值变为真的数据,尽管当我加载游戏场景时它不会保存这些数据因此不要在 if 语句中运行什么。感谢您的帮助,如果需要,我会回答任何问题。
附加信息:当按钮单击 StoreView 时调用函数 ChoseWhiteSkin()。
这是我的代码:
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 this for initialization
void Start () {
Scene currentScene = SceneManager.GetActiveScene ();
string sceneName = currentScene.name;
if (sceneName == "GameScene") {
if (didwhiteskin) {
Debug.Log ("this ran");
//This where I will put function to change skin but the issue is the if statement never being ran
}
}
else if (sceneName == "StoreView") {
}
}
// Update is called once per frame
void Update () {
}
public void ChoseWhiteSkin() {
PlayerPrefs.Save();
didwhiteskin = true;
}
}
【问题讨论】:
-
在提问前谷歌您的问题。这不是一件难事。这个问题最糟糕的部分是它的标题与重复的问题相同。
标签: c# unity3d scene saving-data