当我的玩家与门碰撞时,有没有办法加载场景?
我正在努力做到这一点,以便当我的玩家获得五分并且他们与门相撞时,我的游戏的菜单屏幕就会出现。我认为这段代码很好,但当我与门碰撞时,主菜单不会显示。谁能帮我解决这个问题吗?下面是我的代码:
private void OnTriggerEnter(Collider door)
{
if(door.tag == "Door" && points == 5)
{
SceneManager.LoadScene("MainMenu");
}
}
}
我也使用 unityengine.scenemanagement 。包括点在内的其余代码工作正常,只是场景的加载不起作用。
I'm trying to make it so when my player gets five points and they collide with the door, the menu screen for my game shows up. I thought this code was fine but the main menu won't show when I collide with the door. Can anyone help me fix this? Here is my code below:
private void OnTriggerEnter(Collider door)
{
if(door.tag == "Door" && points == 5)
{
SceneManager.LoadScene("MainMenu");
}
}
}
Im also using unityengine.scenemanagement too. The rest of the code including the points works fine it's just the loading of the scene that won't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有些场景还没有加载到构建设置中,因此从当前场景跳转到其他场景时,无法加载其他场景。您必须将要使用的所有场景加载到构建设置中的萌芽列表中的场景中。方法:加载场景后,单击FILE菜单的构建设置选项,打开构建设置菜单,然后单击菜单中的“添加当前”按钮。您可以看到当前场景已添加到构建设置菜单列表中。以这种方式打开其他场景,并将其添加到UI设置菜单中的萌芽列表中的场景中。添加完所有场景后,保存项目并再次运行,希望对您有帮助
Some scenes have not been loaded into the build settings, so when jumping from the current scene to other scenes, other scenes cannot be loaded. You must load all the scenes you want to use into the scenes in buding list in the build settings. Method: After loading a scene, click the build settings option of the FILE menu, open the build settings menu, and then click the "add current" button in the menu. You can see that the current scenes are added to the build settings menu list. Open other scenes in this way and add them to the scenes in buding list in the uild settings menu. After adding all the scenes, save the project and run it again, I hope it can help you
这里发生了四件事,因此您应该检查所有这些事情才能找到问题。
Debug.Log()
放在OnTriggerEnter
中,以确保它确实被调用door.tag
以确保它匹配“门。”请注意,它区分大小写。points
以确保该值匹配 5。或者
场景索引从 0 开始,并根据场景在构建设置中的排列顺序进行计数。可以在“文件”>“文件”中找到。 构建设置
There are four things happening here, so you should check all of them in order to find your problem.
Debug.Log()
inOnTriggerEnter
to make sure that it's actually being calleddoor.tag
to make sure that it matches "Door." Note that it's case sensitive.points
to make sure that the value matches 5.Or
Scene indexes begin at 0 and count up according to the order the scenes are arranged in your build settings. That can be found in File > Build Settings