- Home /
Photon Network MultiPlayer names Help C#
The title says what I am trying to do. I have read through the Photon API, and tons of threads, but I still can not for my life get names to work. So this is what I currently have.
When you log on, I have this script.
using UnityEngine;
using System.Collections;
public class SetName : MonoBehaviour {
private bool setname = false;
public GameObject Menu;
// Use this for initialization
void Start () {
}
void OnGUI(){
if(!(PhotonNetwork.connectionStateDetailed.ToString () == "Joined")){
return;
}
if(setname){
return;
}
PhotonNetwork.player.name = GUI.TextField(new Rect(0, 0, 100, 100), PhotonNetwork.player.name);
if(GUI.Button(new Rect(Screen.width / 2 + 50, Screen.height/2 -50 , 100, 100), "Enter")){
if(PhotonNetwork.player.name == ""){
Debug.LogError("Enter A Name!");
}else{
Menu.SetActive(true);
setname = true;
}
}
}
// Update is called once per frame
void Update () {
}
}
Ok, so now lets say my player is called "Bob."
When I spawn my player it's PhotonView displays "Bob," as its name.
From this I can work out that I have set the name properly.
So if I build this and run the game as well as unity, I can try this two players. So in unity I call my player "Player 1", and in the other game "Player 2". If I look in the unity game object list, I can now see both my players. If I click on the player controlled though unity, it is called "Player 1." But when I click on the other one, it says that it has not been named.
What am I doing wrong?
Any one? I am currently really stuck on this, and I have been trying for the last two days to get it to work. Any help would be great.
Answer by Baenor · Nov 24, 2014 at 08:20 AM
Honestly i don't think it's an error. If you don't serialize the name, or if you don't use an RPC it's normal that YOU as the Unity Editor don't see changes that happened in other game istances.
I can ensure you that everything will be going to be fine, if you script everything correctly because when you are doing for example a chat script, or a shooting script, you will use an RPC function that will be executed in every instance with the parameters that you set from one....
i hope i helped you
Would it be a good idea to run an RPC when a player joins containing the name? Photon network contains a player name function, but have not been able to get it to work. Is there a tutorial that I have missed that explains how to use the photon name function? I have been able to get the names working, by using the serialise function, but I am sure there is a more appropriate way of getting player names.
Answer by tobiass · Dec 02, 2014 at 09:17 AM
You only have to set PhotonNetwork.playerName to set "this client's" user's name. This is synchronized automatically in a room.
Per networked object, you can get the PhotonView component and access the owner.name.
Take a look at ShowInfoOfPlayer.cs (in newer PUN packages). It's a component which you could add to a character prefab.
Answer by InfernoZYB · Mar 02, 2015 at 06:50 AM
A little late but this script works fine all you gotta do is make a text mesh and assign it.
public TextMesh text;
// Use this for initialization
void Start () {
text.text = photonView.owner.name;
}
// Update is called once per frame
void Update () {
}
Your answer
Follow this Question
Related Questions
'MonoBehaviour' does not exist in the namespace 'Photon'.. 1 Answer
Proton Integration w/Unity Tutorials 1 Answer
How To Setup Character To Benefit FPS 2 Answers
Problem with UFPS and photon 1 Answer
Photon Network Muzzleflash 0 Answers