简体   繁体   English

如何获得所有玩家在光子中的位置

[英]How to get the position of all the player in Photon

I want to know how to get the position of all available player in the network. 我想知道如何获取网络中所有可用播放器的位置。 So how can I update my script ? 那么如何更新脚本?

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++;
        }
    }
}

Each client can set it's player's custom properties with SetCustomProperties, even before being in a room. 每个客户端甚至可以在进入房间之前,都可以使用SetCustomProperties设置其玩家的自定义属性。 They are synced when joining a room. 加入会议室后,它们将同步。

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

For further reading, you should try following tutorial(It will give you a stronger idea how to get and sync positions): http://doc.photonengine.com/en/pun/current/tutorials/tutorial-marco-polo#_Toc317517599 为了进一步阅读,您应该尝试按照教程进行操作(它将为您提供一个更强的想法,如何获取和同步职位): http : //doc.photonengine.com/en/pun/current/tutorials/tutorial-marco-polo#_Toc317517599

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM