- Home /
RPC Player Name and show it above head
Hi!
i've been facing with this problem for a week, and still cant solve....... I need every Player to share his data (including characterName) with others and to place it above.
So here's my logic: 1. Having logged in we have characterSelection scene. Having selected player to log in we make the next:
//OnSelectedChar
public void CreatePlayer(string r)
{
//this is character data: Each element of array keeps different data (0 - name; 1 - race e.t.c...)
playerInfo.GetComponent<EnteringPlayerInfo>().info = this.GetComponent<PlayerData>().FindPlayerArray(this.GetComponent<PlayerData>().FindPlayer(enteringCharacterName));
Application.LoadLevel(playerInfo.GetComponent<EnteringPlayerInfo>().info[23]);
}
We have GameObject playerInfo with EnteringPlayerInfo script and this GO won't be destroyed in order to make player later read that data.
Then we create a server and build player:
void OnServerInitialized() { CreatePlayer(); } void CreatePlayer() { connected = true; camera.enabled = false; camera.gameObject.GetComponent<AudioListener>().enabled = false; _go = (GameObject)Network.Instantiate(PlayerPrefab, spawnPointGo.transform.position, spawnPointGo.transform.rotation, 1); _go.transform.GetComponentInChildren<Camera>().camera.enabled = true; _go.transform.GetComponentInChildren<AudioListener>().enabled = true; }
Then we get our character's data from that undestroyed GameObject PlayerInfo:
myPlayerdata = GameObject.Find("playerInfo").GetComponent<EnteringPlayerInfo>().info;
And the last step: here i try to share my data with other players but no one see it. Only My character Gets My Data....
if (networkView.isMine) { if (!dataSet && myPlayerdata.Length > 0) { networkView.RPC("AdjustPlayerDataOnEnterWorld", RPCMode.All, this.networkView.viewID); } } [RPC] public void AdjustPlayerDataOnEnterWorld(NetworkViewID id) { NetworkView view = NetworkView.Find(id); view.GetComponent<Player>().characterName = myPlayerdata[0]; //view.GetComponent<Player>().characterName = "name" + UnityEngine.Random.Range(); !!!It was working...!!! every character saw other's name correctly view.GetComponent<Player>().level = int.Parse(myPlayerdata[1]); view.GetComponent<Player>().raceID = byte.Parse(myPlayerdata[2]); view.GetComponent<Player>().curEnergy = int.Parse(myPlayerdata[3]); view.GetComponent<Player>().maxEnergy = int.Parse(myPlayerdata[4]); view.GetComponent<Player>().money = int.Parse(myPlayerdata[5]); view.GetComponent<Player>().meleeAttackRange = float.Parse(myPlayerdata[6]); view.GetComponent<Player>().attackSpeed = float.Parse(myPlayerdata[7]); view.GetComponent<Player>().dodge = float.Parse(myPlayerdata[8]); view.GetComponent<Player>().damage = int.Parse(myPlayerdata[9]); view.GetComponent<Player>().forceDamage = int.Parse(myPlayerdata[10]); view.GetComponent<Player>().critical = float.Parse(myPlayerdata[11]); view.GetComponent<Player>().defRate = int.Parse(myPlayerdata[12]); view.GetComponent<Player>().XP = float.Parse(myPlayerdata[13]); view.GetComponent<Player>().lastPosX = float.Parse(myPlayerdata[14]); view.GetComponent<Player>().lastPosY = float.Parse(myPlayerdata[15]); view.GetComponent<Player>().lastPosZ = float.Parse(myPlayerdata[16]); view.GetComponent<Player>().bbSkill = float.Parse(myPlayerdata[17]); view.GetComponent<Player>().rangeSkill = float.Parse(myPlayerdata[18]); view.GetComponent<Player>().mageSkill = float.Parse(myPlayerdata[19]); view.GetComponent<Player>().shieldSkill = float.Parse(myPlayerdata[20]); view.GetComponent<Player>().defSkill = float.Parse(myPlayerdata[21]); view.GetComponent<Player>().launchSkill = float.Parse(myPlayerdata[22]); view.GetComponent<Player>().lastLoc = myPlayerdata[23]; view.GetComponent<Player>().gender = myPlayerdata[24]; dataSet = true; }
here i try to show my name above head. Every player has NameAbove child GameObject wich contaions GUIText:
void Update()
{
this.gameObject.transform.FindChild("NameAbove").GetComponent<GUIText>().text = characterName;
}
I beg u guys, help me please to solve this annoing problem. Every one recieves only his data. I cant share it with others.
P.S. In method AdjustPlayerDataOnEnterWorld() when i used view.GetComponent().characterName = "name" + UnityEngine.Random.Range();
random name generations IT WORKED PERFECTLY over Network. It was synchronized successfully.
OR IF THE REASON IS IN THE METHOD OF SETTING DATA(WITH INDESTROYING GAMEOBJECT BEFORE SERVER WAS CREATED); HOW TO CREATE PLAYER GO OR PLAYERDATAINFO GO BEFORE SERVER WAS INITED......
Thanx!