unity3d - Unity Networking: Restore server objects on scene after change scene
问题描述
I use High-level API and I have a SceneA and SceneB.
SceneA has a couple spawned objects. After a new connection, each client receives objects list and spawn it.
But when I change networkScene A to SceneB and go back I see no objects on SceneA that were be rendered before.
Is there any solution how to get back to SceneA and refresh scene objects according to network SceneA instance?
In the SceneA I use something like this:
public override void OnStartServer()
{
SpawnObjects();
}
解决方案
请记住,每次加载场景时都应该生成网络对象。
因此,如果它们没有“自动”生成,则可能是您没有设置任何逻辑来执行此操作。
所以工作流程应该是这样的:
SceneA 有一个预制件,当 Starts -> Spawner 时 SPAWNS 对象
当玩家连接到场景时,将创建 Spawner,并在其 Start() 函数中生成东西。
当你移动到场景 B 时,如果你没有设置 DonDestroyOnLoad() 之前的对象,将在 B 上消失
但是如果你再次回到 A,因为游戏再次“创建”场景 A,spawner 将再次创建,并再次生成这些东西。
推荐阅读
- php - 需要帮助将 div 样式添加到 php echo 语句
- python-3.x - Discord.py 重写 - YoutubeDL 播放音乐的来源是什么?
- c# - 如何从 IExceptionFilter.OnException() 返回源视图
- ruby-on-rails - 什么时候在 sidekiq 中创建工作和子工作的正确策略是什么?
- r - 如何制作嵌套循环以从列表中提取我需要的元素
- python - 在调用方法期间接收 DeferredAttribute 而不是值
- c++ - 允许继承类使用相同的功能
- javascript - 对比 chart.js 数据标签颜色与背景
- discord - 如何限制机器人可以发送给 1 个用户的消息
- c++ - opengl中的多个聚光灯不起作用