简体   繁体   English

Unity 2D:我怎样才能翻阅特定的场景序列,而不丢失我的分数数据然后检索我的分数数据?

[英]Unity 2D: How can I flip through a specific sequences of scenes, not lose my score data and then retrieve my score data?

I'm new to unity and C# and I have a few questions.我是统一和 C# 的新手,我有几个问题。 Here's the context: I've created 7 different scenes which are basically different mini-games.这是背景:我创建了 7 个不同的场景,它们基本上是不同的迷你游戏。 My goal is the following: At the start, the participant selects mode 1 or mode 2. If they chose mode 1, scenes 1,2 and 3 should be played next.我的目标如下:一开始,参与者选择模式 1 或模式 2。如果他们选择模式 1,接下来应该播放场景 1,2 和 3。 If they choose mode 2, scenes 2,4,5,6,7 should be played next.如果他们选择模式 2,接下来应该播放场景 2,4,5,6,7。 At the end of the mini-games, I want to show the participant's score for all mini-games with visual graphics.在小游戏结束时,我想用视觉图形显示参与者在所有小游戏中的得分。

So here are my questions:所以这是我的问题:

  1. How can I set my game in such a way that when the participant selects 'mode 1', the specific scenes 1, 2 and 3 are played?如何设置我的游戏,当参与者选择“模式 1”时,播放特定场景 1、2 和 3? Or if they select 'mode 2', scenes 2, 4, 5, 6, and 7 are played?或者如果他们 select '模式 2',播放场景 2、4、5、6 和 7? And is their a way to make them play in a random order?他们是一种让他们以随机顺序播放的方法吗?

  2. How can I save the scores of every mini-game so I can access them at the end and use the scores to make graphics?如何保存每个迷你游戏的分数,以便在最后访问它们并使用分数制作图形?

For the scene order, I did somethig like this:对于场景顺序,我做了这样的事情:

void Start()
    {
        RandNum = Random.Range(0, 8);

        if (RandNum == 0)
        {
            SceneManager.LoadScene(MiniGame1);
        }

        if (RandNum == 1)
        {
            SceneManager.LoadScene(MiniGame2);
        }

        if (RandNum == 2)
        {
            SceneManager.LoadScene(MiniGame3);
        }

...etc. ...ETC。 Would this work?这行得通吗?

And for the score saves, when I searched online, I found that I could use PlayPrefs.SetIn("Score mini-game 1", score1) for example.而对于分数保存,当我在网上搜索时,我发现我可以使用 PlayPrefs.SetIn("Score mini-game 1", score1) 例如。 Is this a good method?这是一个好方法吗? and if so, how would I retrieve this information at the end?如果是这样,最后我将如何检索这些信息?

Thank you so much for your help:)非常感谢你的帮助:)

To get your score from PlayerPrefs use PlayerPrefs.GetInt要从 PlayerPrefs 中获取您的分数,请使用PlayerPrefs.GetInt

For Scene loading sequence you can create some ScriptableObject with level queue presets (like int arrays for each mode).对于场景加载序列,您可以创建一些具有级别队列预设的ScriptableObject (例如每种模式的 int arrays)。

For overall architecture I would create some gameobject that will be preserved through all game lifecycle (ie not being destroyed after new scene is loaded) and use that gameobject to hold your game manager.对于整体架构,我将创建一些将在整个游戏生命周期中保留的游戏对象(即在加载新场景后不会被销毁)并使用该游戏对象来保存您的游戏管理器。 For that use DontDestroyOnLoad .为此使用DontDestroyOnLoad But this method may be not ideal for your case, so give it some thoughts before choosing some approach.但是这种方法可能不适合您的情况,因此在选择某种方法之前先考虑一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM