- Home /
Server don't receiving RPC values
Hi. There is my code, I using new pro version of Unity 3D.
public static string playerName = "EMPTY";
void OnConnectedToServer() {
//CLIENT SIDE
networkView.RPC("setPlayerName", RPCMode.All);
}
[RPC]
public void setPlayerName() {
Debug.Log(Login.playerName);
playerName = Login.playerName; // Login is a class.
}
//This part working great, but server don't receive username.
void OnPlayerConnected(NetworkPlayer player) {
//SERVER SIDE
notification = playerName + xxxx; // Here playerName == EMPTY. Why ?
}
I have attached to main camera -- networkView, and scripts.
you don't give any value in the networkview and rpc function
networkView.RPC("setPlayerName", RPC$$anonymous$$ode.All, username);
[RPC] public void setPlayerName(string username) { Debug.Log(Login.playerName); playerName = Login.playerName; // Login is a class. }
You can use the following variable types as parameters to RPCs:-
int float string NetworkPlayer NetworkViewID Vector3 Quaternion
So you're saying that your RPC is not sending any information, when you're not telling it to send anything
Then you say you're not receiving anything either... maybe because you're not telling it that you can recieve something...
sigh
Ok guys, I now have
public string user = "E$$anonymous$$PTY";
public void Connect(string username) {
Network.Connect("ip", port, "password");
Debug.Log(username); // Here username return "siOnzee".
setNickName(username);
}
public void setNickName(string username) {
networkView.RPC("setPlayerName", RPC$$anonymous$$ode.All, username); // Here I got NullReferenceException Network$$anonymous$$anager.setNickName (System.String username) (at Assets/C#/Network$$anonymous$$anager.cs:85)
}
[RPC]
public void setPlayerName(string username) {
Debug.Log(username);
user = username;
}
What I now doing wrong ?
Firstly, you aren't indenting -_-
Secondly, you need a NetworkView
attached to the object for this to work.
To first: I have indenting, but I removed it here. I have networkView attached to $$anonymous$$ain Camera on server side and client side too. Screens:
Client SIDE
Server SIDE
Core:
public class Core : $$anonymous$$onoBehaviour {
private $$anonymous$$ySQL mysql;
private Network$$anonymous$$anager network$$anonymous$$anager;
private Login login;
private FirstPlay firstplay;
private Hud hud;
private Loading loading;
private Typ typ;
void Start () {
mysql = new $$anonymous$$ySQL(this);
network$$anonymous$$anager = new Network$$anonymous$$anager(this);
login = new Login(this);
firstplay = new FirstPlay(this);
hud = new Hud(this);
loading = new Loading(this);
}
public $$anonymous$$ySQL get$$anonymous$$ySQL() { return mysql; }
public Network$$anonymous$$anager getNetwork$$anonymous$$anager() { return network$$anonymous$$anager; }
public Login getLogin() { return login; }
public FirstPlay getFirstPlay() { return firstplay; }
public Hud getHud() { return hud; }
public Loading getLoading() { return loading; }
}
on$$anonymous$$ouseDown Login I call: core.getNetwork$$anonymous$$anager().Connect(username.text);
public void Connect(string username) {
Network.Connect("127.0.0.1", 25000, "frelaniaAAAGa$$anonymous$$eeee4156");
Debug.Log(username);
setNickName(username);
}
public void setNickName(string username) {
networkView.RPC("setPlayerName", RPC$$anonymous$$ode.All, username);
}
[RPC]
public void setPlayerName(string username) {
Debug.Log(username);
user = username;
}
void OnPlayerConnected(NetworkPlayer player) {
//SERVER
if (Network.isServer) {
notification = user + " has connected.";
writeToLog(notification);
Debug.Log("Player " + user + " has connected.");
PlayerList.Add(user);
}
}