Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 TheBombix95 · Aug 24, 2014 at 12:01 AM · multiplayernetwork

Multiplayer Name Labels problem

Hi Unity folks, It's been a while since my last question and I need your sweet help for a multiplayer issue that I've encountered two days ago.

I'm setting up an Online World War 2 battle game where you can control an airplane and you can (eventually) customize it as you like.

Random User: "Hey man, that sounds like a game copy!" Well, ye...NO!

Ahah, just kidding!

I'm trying to display the player name and aircraft name above a player, with no luck (otherwise I wouldn't have come here, right?)

You can already control your aircraft and fly around, but it's really hard to see other players since the map it's quite big ;) . I've attempted to store the username that a client entered in a GUI text field and then send it to a spawner script (with a networkView attached to it) with an RPC call. It pops an error saing >> "No RPC can be sent since no connection was started" << I thought that it can't send that RPC because it's still connecting to the server and so...nothing happens.

Then in the spawner script I've changed so that when it is already connected it sends to the spawned player the RPC to set the name but then nothing happens because I can't send the name typed in by the user in the client to the spawner.

I was thinking about storing all the players and the corresponding aircraft name into a List ordered by player's id in the server and then send those names to all the players connected, but...I don't really know how to do it.

By the way I'll put down the Client, Server and the Player name script to see if you guys can help me out.

I'm not asking to do an entire script for me, I'm asking if someone can enlight me on this subject (network names) and eventually put some examples on how to do an array storing all players and send those stored values to all the others.

======================================= Client script

 var yourName : String = "";
 
 var SpawnPointObjectBlue : GameObject;
 @HideInInspector
 var currentMenu : String;
 var MenuSize : Vector2;
 
 @HideInInspector
 var data : HostData[];
 
 function Awake() 
 {
     MasterServer.RequestHostList("Warbirds PvP");
     currentMenu = "UserSettings";
 }
 
 function OnGUI() {
     if(currentMenu == "ServerList")
         GUI.Window(0,Rect((Screen.width/2)-(MenuSize.x/2),(Screen.height/2)-(MenuSize.y/2),MenuSize.x,MenuSize.y),Client_Window,"Server List");
     else if(currentMenu == "UserSettings")
         GUI.Window(1,Rect((Screen.width/2)-(MenuSize.x/2),(Screen.height/2)-(MenuSize.y/2),MenuSize.x,MenuSize.y),User_Window,"User Settings");
 }
 
 function Client_Window (windowID : int)
 {
     if(GUILayout.Button("Go to User Settings"))
         currentMenu = "UserSettings";
     GUILayout.BeginHorizontal();
     
     
     for (var element in data)
     {
         
         var connections : int = parseInt(element.connectedPlayers)-1;
         var connectionsLimit : int = parseInt(element.playerLimit)-1;
         var serverConnections = connections.ToString() + " / " + connectionsLimit.ToString();
         GUILayout.Box(element.gameName);
         GUILayout.Box(serverConnections);
         GUILayout.Box(element.comment);
         
         if (GUILayout.Button("Connect"))
         {
             Network.Connect(element);
             currentMenu = "";
             //GameObject.FindWithTag("Respawn").networkView.RPC("SpawnPlayer",RPCMode.AllBuffered, yourName);
         }
     }
     GUILayout.EndHorizontal();
 }
 
 function User_Window (windowID : int)
 {
     yourName = GUILayout.TextField(yourName); //This is where I store the player name
     if(GUILayout.Button("Go to Server List"))
     {
         currentMenu = "ServerList";
         data = MasterServer.PollHostList();
     }
 }


======================================= Spawner script

 var Player : GameObject;
 var myName : String;
 
 function OnConnectedToServer ()
 {
     if(Network.isClient)
     {
         if(Player)
         {
             var InstPlane : GameObject = Network.Instantiate(Player, transform.position, transform.rotation, 0);
             InstPlane.networkView.RPC("SetMyNames",RPCMode.AllBuffered, myName, "P39D Airacobra");
         }
     }
 }
 
 function OnPlayerDisconnected (player : NetworkPlayer) 
 {
     Network.RemoveRPCs(player);
     Network.DestroyPlayerObjects(player);
 }
 
 @script AddComponentMenu("Network/Spawner Script");

======================================= NameLabel script

 var AirplaneName : String = "";
 
 var NetworkPlayers : GameObject[];
 
 var screenPos : Vector2;
 var MyCam : Camera;
 var myOffset : float = 1.0;
 
 function Update ()
 {
     NetworkPlayers = GameObject.FindGameObjectsWithTag("Player");
     
     for(var p : GameObject in NetworkPlayers)
     {
         screenPos = MyCam.WorldToScreenPoint(p.transform.position);
     }
 }
 
 function OnGUI ()
 {
     for(var p : GameObject in NetworkPlayers)
     {
         if(p.networkView.isMine == false)
         {
             GUI.Label(new Rect(screenPos.x-100, Screen.height - screenPos.y-myOffset, 200, 50), p.GetComponent(MultiplayerNameLabel).PlayerName+"/n"+"["+p.GetComponent(MultiplayerNameLabel).AirplaneName+"]");
         }
     }
 }
 
 @RPC
 function SetMyNames (p_name : String, a_name : String)
 {
     PlayerName = p_name;
     airplaneName = a_name;
 }
 
 

I hope you guys can help me out cause I can't go on without names above players (well you know better than me!)

Thanks in advance

See you soon

Bombix95

Comment
Add comment
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

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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Simple Multiplayer Animation Question 1 Answer

Network RPC buffer issue 0 Answers

How to use Network.Instantiate Groups 1 Answer

Displaying players name above in multiplayer 1 Answer

How I can convert data to Wifi/ Multiplayer/ Network 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges