- Home /
Shooting myself
Im making an online game with photon network, and i have this script attached to my arrow prefab, but when i shoot my bow i hit and take damage from myself. I dont understand why,
void OnTriggerEnter (Collider other)
{
if (other.gameObject.tag == "Player") {
if (other.gameObject.GetComponent<PhotonView> ().isMine) {
Debug.Log ("shooting myself");
return;
} else if (!other.gameObject.GetComponent<PhotonView> ().isMine) {
other.transform.GetComponent<PhotonView> ().RPC ("TakeDamage", PhotonTargets.All, WeaponDamage, PhotonNetwork.player.name);
hasCollide = true;
_hitTimer = 0;
}
}
}
$$anonymous$$y guess is, that every instance is spawning the arrow. That would mean, that on the network instances, the else if is correct, sending the RPC, which again means that every instance receives damage.
I would recommend to check for networkview.is$$anonymous$$ine first, then go into the ifs. This will avoid all other arrows to even do anything.
Try to print the name of the other object within your method?, Is it the player game object? is it another? Isn't there a chance that your arrow is triggering the collision with the player just after it is spawned?