嗨,我对代码非常陌生,我真的很努力。我只是尝试为二十一点游戏创建一个简单的下注系统,在该系统中您下注并保存了值,然后将其转移到我的下一个场景(即游戏场景)中。因此,基本上,我在一个名为BetScene的场景中创建了一个按钮,当按下该按钮时,它会在betamount中添加25,并从playeramount中删除25。一旦玩家对他们所放置的钱感到满意,他们就按下第二个按钮PlaceBet。当按下该按钮时,游戏场景将加载,因此我要做的是保存放置的数量并将其显示在游戏场景中。希望这有意义,我真的需要帮助,我真的想学习谢谢
- 积分
0 - 话题
0 - 评论
3210 - 注册排名
1948
好的,首先,这听起来并不像您应该为此使用多个场景,所以我会说“在这种情况下,请重新考虑您的体系结构和场景流程”。但是我也在这里,回答您的问题,所以让我们来做。
A great way of sharing data between scenes is using a
ScriptableObject
as a data container. You simply create the class of the data you want to use in multiple scenes and then create an instance of yourScriptableObject
as an asset in your Assets-folder.This asset can then be assigned to all components that need to use it for data transfer. It is basically like a texture that is painted on in one scene and read from in another scene.
You can even improve on this by creating a kind of "data binding" using these
ScriptableObject
assets as variables. There is a great talk about that topic from 2017 on Unitys YouTube channel: Unite Austin 2017 - Game Architecture with Scriptable Objects