- Home /
Displaying Damage Text/Text Mesh to all clients
Hiya,
So I'm trying to display damage text using a text mesh above players that get damaged over the network, however I can only get it to display to the player that has been damaged.
Right now I have a HealthDamageScript attached to the player prefab that looks like this:
...
public class HealthDamageScript : NetworkBehaviour {
...
public Transform damageTextPrefab;
...
public void TakeDamage(int damage)
{
if (!isServer)
{
return;
}
...
RpcDamageText(damage);
...
}
...
[ClientRpc]
void RpcDamageText(int damage)
{
if (isLocalPlayer)
{
Vector3 pos = transform.position;
pos.y += gameObject.transform.localScale.y;
GameObject text = Instantiate(damageTextPrefab, pos, Quaternion.identity).gameObject;
text.GetComponent<TextMesh>().text = "-" + damage;
}
}
}
How would I get the RPC to be sent to all clients rather than only the player that has been damaged?
Answer by Mike-Geig · Feb 03, 2017 at 03:42 PM
It is being sent to all clients, you are just filtering it with the line if (isLocalPlayer)
If you remove that IF statement then all copies of the damaged player (both the one local and all the remote copies) will see the damage above their heads
Your answer
Follow this Question
Related Questions
Text object can't be searched for with GameObject.Find 3 Answers
Why is networkbehaviour underlined in green? 1 Answer
networkview + GUI 2 Answers
Multiplayer pause menu won't disappear 0 Answers