I’m creating a simple LAN multiplayer game where one player is server and the other one is client. I’m trying to inform player_1 that he killed player_2 (or that player_2 killed player_1). I wrote this code but it doesn’t work. It displays text on server (host player). For example if player_1 (client) kills player_2 (host), then the text will be displayed on hosts screen (instead of clients) saying “You killed player_2”, and if host (player_2) kills client the same will happen, it will say “You killed player_2”.
Here’s function that’s being called when a player needs to take damage.
public void TakeDamage(float amount, NetworkInstanceId NetID){
if(isServer){
m_Health-=amount;
if(m_Health<0.1f){
RpcOnDeath(NetID);
m_Health = 100f;
}
}
}
NetID is network identity of the shooter and it’s being passed to take TakeDamage and then to RpcOnDeath function.
Since I want to tell player_1 that he killed player_2 I try to send a message like this:
[ClientRpc]
void RpcOnDeath(NetworkInstanceId ID){
/*
Respawn code...
*/
// Find game object on server with this ID and run function
GameObject Killer = NetworkServer.FindLocalObject (ID);
PlayerHealth KillerHealth = Killer.GetComponent<PlayerHealth>();
KillerHealth.KillNotification (MyNickname);
}
And KillNotification is a simple function that only displays text to killer like this:
public void KillNotification (string Killname){
KillConfirmation.GetComponent<Text> ().text = "YOU KILLED " + Killname;
KillConfirmation.GetComponent<Text>().enabled = true;
}
I can’t figure out what’s wrong. ![]()