【问题标题】:How to get the position of all the player in Photon如何在 Photon 中获取所有玩家的位置
【发布时间】:2017-02-18 07:59:55
【问题描述】:

我想知道如何获取网络中所有可用玩家的位置。 那么如何更新我的脚本呢?

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Pathfinding : MonoBehaviour {
Transform[] Players;
int TotalPlayerCount=0;
void Update() {
    foreach (PhotonPlayer pl in PhotonNetwork.playerList) {
        if (GetComponent<PhotonView> ().isMine) {
            Players[TotalPlayerCount].position= //position of my player
            TotalPlayerCount++;
        } 
        else
        {
            Players[TotalPlayerCount].position=//position of all other player available in the room
            TotalPlayerCount++;
        }
    }
}

【问题讨论】:

    标签: c# unity3d game-engine multiplayer photon


    【解决方案1】:

    每个客户端都可以使用 SetCustomProperties 设置其玩家的自定义属性,甚至在进入房间之前。加入房间时它们会同步。

    Hashtable xyPos = new Hashtable();
    xyPos.Add(1, "10");
    xyPos.Add(2, "-20");
    PhotonPlayer.SetCustomProperties(xyPos, null, true) ;
    

    为了进一步阅读,您应该尝试以下教程(它将让您更清楚地了解如何获取和同步位置): http://doc.photonengine.com/en/pun/current/tutorials/tutorial-marco-polo#_Toc317517599

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 2019-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-11
      • 1970-01-01
      相关资源
      最近更新 更多