- Home /
Multiplayer names problem
I am using the M2H tutorial for my multiplayer networked game. Currently I have name labels for each of the players using 3dtext ad networkview and networkrigidbody attached. I also attached a script to the 3d text that sets the value of the text to the name of the player. The code looks like this:
using UnityEngine; using System.Collections;
public class PlayerInfoText : MonoBehaviour {
public string pname=""; public float health; public Transform thetarget; public string thisName =""; private GameSetup gameSetupScript;
void Awake(){ health = 100;
}
void Start(){ if (!networkView.isMine){ gameSetupScript = GameObject.Find("Generalscripts").GetComponent<GameSetup>(); foreach (FPSPlayerNode playerInstance in gameSetupScript.playerList) { if (networkView.viewID.owner == playerInstance.networkPlayer) { pname=playerInstance.playerName; break;
} }
setName(pname); } transform.gameObject.GetComponent<TextMesh>().text = thisName +"\n" +health; }
void Update(){ transform.LookAt(transform.position + Camera.main.transform.forward);
}
When only two players are logged in (the server and 1 client). Everything works good, the names show up properly. However, when 3 or more are logged in there are problems. The server looks good, all players are labeled correctly, however, on each client all the ships have the servers name. I need all the clients to have all the correct names for the other players' ships.
Thank you.
Answer by AnaRhisT · Jun 22, 2010 at 06:38 PM
Use PlayerPrefs
function, a WORKING example is showed in leepo's networking tutorial. folder name "Example4". - In the first scene u write a name and it saves it with playerprefs.setsting, and getstring.
I've tried getting the name with PlayerPrefs.GetString("playerName"), but that just sets all the opposing players labels to the name of the localplayer.
Is there a way to access the PlayerPrefs of the other players?
I've been going over Leepo's tutorial more and more and finally got it to work the way I needed it to.
Answer by mlkielb 1 · Jun 22, 2010 at 07:11 PM
I've tried getting the name with PlayerPrefs.GetString("playerName"), but that just sets all the opposing players labels to the name of the localplayer.
Is there a way to access the PlayerPrefs of the other players?
When restating a question please use the comment button
Again, everything is showed there, as u can see all the names are stored in the Scoreboard with OTHER names - which is exactly like the 3D Text.
Your answer

Follow this Question
Related Questions
Networking Player Nametag 1 Answer
A name For the Character Please Help 3 Answers
Network object references to each other 1 Answer