Unity3d_Multiplayer Netwoking6

Testing Player Movement Online

测试玩家运动在线

Test Player Movement on the Host

测试玩家在主机上的移动。

At this point, the Player GameObject only moves on the Client.

此时,玩家的游戏对象只会移动到客户端。

It is not networked in any way.

它不以任何方式联网。

To test:

测试:

Enter Play Mode.

进入播放模式。

In Play Mode, the NetworkManagerHUD will show the default user interface:

在Play模式下,NetworkManagerHUD将显示默认的用户界面:


Unity3d_Multiplayer Netwoking6_第1张图片
在Play模式下,NetworkManagerHUD将显示默认的用户界面

Click the LAN Host button on the in-game UI to start the game as the Host.

点击游戏内UI上的局域网主机按钮开始游戏作为主机。

The NetworkManager will create a new player GameObject in the scene from the referenced player prefab.

NetworkManager将在被引用的播放器预置的场景中创建一个新的播放器游戏对象。

The NetworkManagerHUD will change the controls to show that the Server is active.

NetworkManagerHUD将更改控件以显示服务器是活动的。


This game is running as a “Host” - which is a Server and a Client in the same process.

这个游戏是作为一个“主机”运行的——在同一个进程中是一个服务器和一个客户端。

For more information, please see the page on Network Concepts.

有关更多信息,请参阅有关网络概念的页面。

To test moving the player GameObject in the scene:

在场景中测试玩家的游戏对象:

Press the WASD or arrow keys to move and turn the player

按下WASD或箭头键移动和旋转播放器。

To stop hosting the game:

停止举办游戏:

Select the “Stop” button on the in-game UI.

在游戏界面中选择“停止”按钮。

This will return the game to offline-mode.

这将使游戏返回到离线模式。

To end this test:

结束这个测试:

Exit Play Mode in the editor.

在编辑器中退出播放模式。

Test Player Movement on a Client

测试玩家在客户端上的移动。

To test player movement on a Client there will need to be two instances of the game running simultaneously;

要在客户端测试玩家的移动,需要有两个同时运行的游戏实例;

one of which will be the Host.

其中之一就是主持人。

One instance can be run from the editor, but the second needs to be run from a build of the game, so first we must create a build of the current project if we are to test movement on a client.

一个实例可以从编辑器中运行,但是第二个需要从游戏的构建中运行,因此,如果要在客户机上测试移动,首先必须创建当前项目的构建。

Add the scene Main to the build settings window.

将场景Main添加到构建设置窗口。

Save the project.

保存项目。

Build and Run this scene only as a standalone application.

构建并运行这个场景只是作为一个独立的应用程序。

When the build is running, select the windowed checkbox and a choose a resolution low enough to have on screen alongside the editor.

当构建运行时,选择窗口复选框,然后选择一个足够低的分辨率,并在编辑器旁边显示。

The standalone player will now start and show the in-game UI from the NetworkManagerHUD.

独立播放器现在将开始并显示来自NetworkManagerHUD的游戏内UI。

Click the Host button from the in-game UI to start this game as a Host.

单击游戏内UI中的主机按钮以作为主机启动此游戏。

A player GameObject should be created by the NetworkManager.

玩家的游戏对象应该由NetworkManager创建。

To test moving the Host’s player GameObject in the scene:

测试在场景中移动主机的玩家游戏对象:

Press the WASD or arrow keys to move and turn the player

按下WASD或箭头键移动和旋转播放器。

After moving the player GameObject in the scene:

在场景中移动播放器的游戏对象:

Return to Unity.

回到Unity。

Enter Play Mode

进入播放模式

The game will now run in the editor and show the in-game UI from the NetworkManagerHUD.

游戏将在编辑器中运行,并从NetworkManagerHUD显示游戏内UI。

Click the LAN Client button from the in-game UI to connect to the Host as a Client.

单击游戏内UI中的LAN客户端按钮以连接到主机作为客户端。

There should be two player GameObjects;

应该有两个玩家的游戏对象;

one for the local player on the Host and one for the remote player for this Client.

一个用于本地播放器,另一个用于该客户端的远程播放器。

To test moving the Client’s player GameObject in the scene:

在场景中测试客户的播放器游戏对象:

Press the WASD or arrow keys to move and turn the Client's player

按下WASD或箭头键移动并旋转客户端的播放器。

Note how both player GameObjects move in the scene using the same input.

注意两个玩家的游戏对象如何在场景中使用相同的输入。

Switch back to the standalone player.

切换回独立播放器。

Note how the player GameObjects are not in the same location on the Host as they are on the Client.

注意,玩家的游戏对象在主机上的位置与客户机上的不同。

This is because the PlayerController script is not network-aware.

这是因为PlayerController脚本不是网络感知的。

In the current situation, both player GameObjects have the same script attached.

在当前的情况下,两个玩家的游戏对象都有相同的脚本。

Both are processing the same input in each separate instance of the game.

它们都在游戏的每个单独的实例中处理相同的输入。

The Host and Client are aware of each other, and the NetworkManager has created a player GameObject in each instance of the game for each player, but neither player GameObject is communicating with the Host so their positions are not tracked by the NetworkManager and are therefore not being synchronized.

主机和客户端都知道对方,NetworkManager在每个玩家的游戏中都创建了一个玩家游戏对象,但是玩家的游戏对象都没有与主机通信,所以他们的位置没有被网络管理员跟踪,因此没有被同步。

Close the standalone player.

关闭独立的球员。

Return to Unity.

回到Unity。

Exit Play Mode.

退出播放模式。

你可能感兴趣的:(Unity3d_Multiplayer Netwoking6)