- Home /
Question by
Macchus · Oct 02, 2018 at 06:36 AM ·
multiplayer-networkingrpccommand
Multiplayer - OnTriggerEnter2D Help.(Only working on Host, Not on Clients)
Hi, I curious why OnTriggerEnter2D only works for the host. And not the clients. This is a script used to do damage to another player. The host can damage the client player, but the client doesn't register any hit. It seems as if the function doesn't do anything. Is there a way to make this a [Command]?
Here is the code I have.
private void OnTriggerEnter2D(Collider2D collision) { if (!isLocalPlayer) { return; } if (collision.gameObject.CompareTag("Player")) { GameObject hit = collision.gameObject; Health health = hit.GetComponent<Health>(); if (health != null) { health.TakeDamage(10); } } }
Comment
Answer by HamzaAlrawi · Oct 02, 2018 at 06:49 AM
I am not sure, but probably could be something with the if (!isLocalPlayer)?