(Unity)Network.Instantiate不会在所有客户端上调用

时间:2016-11-07 17:17:51

标签: networking unity3d instantiation multiplayer unity-networking

我正在开发一个小型网络项目,并且无法通过网络实例化对象。当一个人加入服务器时我没有问题...当第二个人加入时我遇到问题 - 第二个人只在第一个人的客户端实例化,而另一个人在第二个玩家的客户端没有看到。我知道Network.Instatiate应该被调用所有客户端,即使他们稍后加入,但它只是没有发生在我身上...看看:

private void SpawnPlayer()
{
    GameObject spawnPoints = GameObject.Find("Spawns");
    GameObject player = (GameObject)Network.Instantiate(playerPrefab, spawnPoints.transform.GetChild(Random.Range(0, spawnPoints.transform.childCount - 1)).transform.position, Quaternion.identity,0);
    //This is just to assign the current player to the shoot button so it knows which one to shoot from
    if (player.GetComponent<NetworkView>().viewID.isMine)
    {
        EventTrigger trigger = shootButton.GetComponent<EventTrigger>();
        EventTrigger.Entry entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.PointerDown;
        currentPlayer = player.GetComponent<Player>();
        UnityEngine.Events.UnityAction<BaseEventData> call = new UnityEngine.Events.UnityAction<BaseEventData>(ShootEventMethod);
        entry.callback.AddListener(call);
        trigger.triggers.Add(entry);
    }
}

enter image description here

1 个答案:

答案 0 :(得分:0)

我认为这是一个客户端问题。每当第二个玩家连接时,你应该调用另一个函数来获取服务器中的每个玩家并在第二个玩家的视图中生成它们。与Code类似的函数。