如何从一个脚本到另一个脚本访问布尔,以便我可以加载多个场景?
我是Unity的菜鸟,我正在尝试制作一个您来到一个区域的游戏,当您走过无敌的盒子时,我已经放了另一个场景。它将继续这样做。在您加载的每个场景中,都会有另一个框来加载下一个场景。但是它也将卸载不直接在您身后的场景。因此,我您可以向前走的地方,您将加载2个场景,其中有1个场景。 自游戏滞后以来,我这样做了,因为我在游戏中拥有的资产量以及它们上的图形。
如果我使用HDRP来制作此游戏,并且所有场景都在彼此的前面,那么地图就没有弯曲。
到目前为止,我提出的是使用盒子并在其上添加触发器来激活将下一个场景加载到其他脚本中的bool,因为该脚本已经在加载场景的地方已经有一个部分。
关于如何解决它或如何将Bool组件从一个脚本到另一个脚本的任何想法,因为它是由Box Collider触发的。因此,当盒子对撞机触发时,您将Bool设置为True,然后将下一个场景加载。
I'm a noob at unity and I'm trying to make a game where you come to an area and when you walk over an invincible box I have placed another scene loads in. And it will keep on going like that. In every scene you load in there will be another box to load the next scene in. But it will also unload scenes that are not directly behind you. So i you where to walk forwards, you would load 2 scenes infron of you and have 1 scenes loaded behind you.
I have done this since my game lags because of the amount of assets I have in the game and the graphics on them.
If it helps I'm using HDRP to make this game and all scenes are in front of each other so there is no bend to the map.
What I have come up with so far is using the box and adding a trigger on it to activate a bool that will load the next scene in a different script since that script has already a part where it loads a scene.
Any ideas on how to solve it or how to get the bool component from one script to another since it is triggered by a box collider. So when the box collider gets triggered you set the bool to true and the next scene loads in.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用单身模式在场景之间发送和保留数据。
这是一个模板,您没有放置代码。
然后,如果您想从另一堂课调用此课程,您只需要这样做:
you can use a Singleton pattern to send and keep data between scene.
Here is one template has you didn't put code.
Then, if you want to call this class from another class you just have to do this :