需要澄清此 AR 多人游戏教程中的一件事

Need clarification of one thing in this AR Multiplayer Tutorial

我正在试验使用本教程制作的简单 AR 多人游戏应用:

https://www.youtube.com/watch?v=n3a-aaSYR8s

SourceCode

有效!但我不确定,为什么以相同方式实例化的 2 个对象位置不同:月亮和玩家。

为什么 "Player" 游戏对象仍然附加到用户的 phone,而 "Moon" 仍然附加到房间中的某个位置?还有为什么实例化后月亮的位置和Player不一样?

它们都是用相同的命令实例化的:

PhotonNetwork.Instantiate ("SampleMoon", Vector3.zero, Quaternion.identity, 0);

如果两者的实例化代码相同,定位的差异是否与预制件本身有关?究竟是什么原因造成的?

再看一下来自 17:16 的视频!

区别不在于实例化,而在于实例化对象(预制件)所附加的组件:

MoonController (used by the Moon) vs PlayerController(玩家使用)


虽然 MoonController 基本上除了注册月亮什么都不做:

void Start () 
{
    // Register this object to the current game controller.
    // This is important so that all clients have a reference to this object.
    GameController.Instance.RegisterMoon (this);
}

Update 方法中 PlayerController 始终设置为相机的 positionrotation(在此应用程序中 "Camera = Players Smartphone" )。我将重要的行标记为粗体:

public Transform CameraTransform;

    private void Start ()
    {
        CameraTransform = FindObjectOfType ().transform;
        // Register this player to the GameController. 
        // Important: all clients must have a reference to this player.
        GameController.Instance.RegisterPlayer (this);

        // Hide your own model if you are the local client.
        if (photonView.isMine)
            gameObject.transform.GetChild (0).gameObject.SetActive (false);
    }

    void Update () 
    {
        // If this player is not being controlled by the local client
        // then do not update its position. Each client is responsible to update
        // its own player.
        if (!photonView.isMine && PhotonNetwork.connected)
            return;

        <b>// The player should have the same transform as the camera
        gameObject.transform.position = CameraTransform.position;
        gameObject.transform.rotation = CameraTransform.rotation;</b>
    }
}

所以在实例化两个对象后的第一帧中,Player 对象已经在 Camera 的位置和旋转上,而 Moon 仍然在它的实例化点上 0,0,0