美文网首页
Unity3d_Multiplayer Netwoking9

Unity3d_Multiplayer Netwoking9

作者: 慕城祉宇流年殇 | 来源:发表于2018-01-10 11:04 被阅读0次

    Identifying the Local Player

    确定当地的球员

    The player GameObjects are currently identical.

    玩家的游戏对象现在是相同的。

    The players cannot identify which GameObject belongs to them in the game.

    玩家不能确定游戏中哪个游戏对象属于他们。

    To identify which GameObject belongs to the local player, we will color the local player GameObject blue.

    为了确定哪个游戏对象属于本地播放器,我们将给本地播放器的GameObject blue着色。

    public override void OnStartLocalPlayer()

    {

        GetComponent().material.color = Color.blue;

    }

    The final script will look like this:

    最后的脚本是这样的:

    PlayerController:

    using UnityEngine;

    using UnityEngine.Networking;

    public class PlayerController : NetworkBehaviour

    {

        void Update()

        {

            if (!isLocalPlayer)

            {

                return;

            }

            var x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f;

            var z = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f;

            transform.Rotate(0, x, 0);

            transform.Translate(0, 0, z);

        }

    public override void OnStartLocalPlayer()

        {

            GetComponen<MeshRenderer>().material.color = Color.blue;

        }

    This function is only called by the LocalPlayer on their Client.

    此函数仅由本地玩家在其客户端调用。

    This will make each player see their local player GameObject as blue.

    这将使每个玩家看到他们本地的游戏对象为蓝色。

    The OnStartLocalPlayer function is a good place to do initialization that is only for the local player, such as configuring cameras and input.

    OnStartLocalPlayer函数是一个用于初始化的好地方,它只适用于本地播放器,比如配置摄像头和输入。

    There are many other useful virtual functions on the NetworkBehaviour base class.

    在NetworkBehaviour基类中还有许多其他有用的虚函数。

    For more information, please see the pages on Spawning or NetworkBehaviour.

    有关更多信息,请参见生成或网络行为的页面。

    Save the script.

    保存脚本。

    Return to Unity.

    回到Unity。

    Build and Run this scene as a standalone application.

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

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

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

    Move the player GameObject.

    玩家GameObject移动。

    Return to Unity.

    回到Unity。

    Enter Play Mode.

    进入播放模式。

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

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

    The player GameObject controlled by the local player should now be blue, while the other player GameObject should remain white.

    由本地玩家控制的玩家游戏对象现在应该是蓝色的,而其他玩家的游戏对象应该是白色的。

    Close the standalone player.

    关闭独立的球员。

    Return to Unity.

    回到Unity。

    Exit Play Mode.

    退出播放模式。

    相关文章

      网友评论

          本文标题:Unity3d_Multiplayer Netwoking9

          本文链接:https://www.haomeiwen.com/subject/nhznnxtx.html