So, I'm using Photon Pun 2 to make a basic multiplayer combat game. When the game starts, two player prefabs are instantiated, one for each player. Each prefab's hand has a "PlayerHand" tag and when the enemy's hand hits the player, the player should take damage, like this:
public class GetCollision : MonoBehaviour
{
public PlayerController me;
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("PlayerHand"))
{
Debug.Log("hit" + Time.deltaTime);
me.TakeDamage(20);
}
}
}
public class PlayerController : MonoBehaviourPunCallbacks
{
public void TakeDamage(float damage)
{
PV.RPC(nameof(RPC_TakeDamage), PV.Owner, damage);
}
[PunRPC]
void RPC_TakeDamage(float damage, PhotonMessageInfo info)
{
currentHealth -= damage;
}
}
The problem I'm having is, as each player's own hand has a "PlayerHand" tag, the players can do damage to themselves. Is there a way to make player take damage only if the "PlayerHand" is not it's own? Something like:
if (PlayerHand != isMe) { takeDamage() }
Or is there some other way to achieve this?
All advice is appreciated!