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

Rum*_*ata 5 c# unity-game-engine augmented-reality arkit

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

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

源代码

有用!但是我不确定,为什么2个被实例化的对象以不同的方式定位:月亮和玩家.

为什么"玩家"游戏对象仍然附着在用户的手机上,而"月亮"仍然附着在房间的某个位置?为什么实例化后月球的位置与玩家不一样?

它们都使用相同的命令进行实例化:

PhotonNetwork.Instantiate ("SampleMoon", Vector3.zero, Quaternion.identity, 0);
Run Code Online (Sandbox Code Playgroud)

如果实例化代码对于它们两者都相同,那么定位的差异是否与那些预制件本身有关?究竟是什么原因导致的

我将非常感谢您的帮助,谢谢您提前!

der*_*ugo 3

再看一下17点16分的视频吧!

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

MoonController(由月球使用)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);
}
Run Code Online (Sandbox Code Playgroud)

获取PlayerController始终设置为方法中相机的position和(在此应用程序中“相机 = 玩家智能手机”)。我将重要的线条标记为粗体:rotationUpdate

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;

        // The player should have the same transform as the camera
        gameObject.transform.position = CameraTransform.position;
        gameObject.transform.rotation = CameraTransform.rotation;
    }
}
Run Code Online (Sandbox Code Playgroud)

因此,在实例化两个对象后的第一帧中,Player 对象已经位于 Camera 的位置和旋转位置,而 Moon 仍保留在其实例化点上0,0,0