• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by epicVoodoo · May 31, 2015 at 08:20 PM · networkphotonrpcnamenetworkview

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.

  1. 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;
         }
    
    
  2. Then we get our character's data from that undestroyed GameObject PlayerInfo:

          myPlayerdata = GameObject.Find("playerInfo").GetComponent<EnteringPlayerInfo>().info;
     
    
  3. 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!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Crystalline · May 31, 2015 at 08:47 PM 0
Share

Try using Rpc$$anonymous$$ode.Others.

avatar image epicVoodoo · May 31, 2015 at 09:35 PM 0
Share

But where?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

get return on networkView.RPC 1 Answer

object naming via network 0 Answers

How to sync position only one time, using Photon Networking 1 Answer

Server & Client Instantiate 0 Answers

Can not make RPC calls during Start() 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges