Search Unity

Third Party (Photon) Player not taking damage

Discussion in 'Multiplayer' started by Moddwyn, Dec 27, 2016.

  1. Moddwyn

    Moddwyn

    Joined:
    Jan 27, 2016
    Posts:
    49
    Shooting script:
    Code (CSharp):
    1. if (Physics.Raycast (ray, out hit, range)) {
    2.                 if (hit.collider.tag == "Player") {
    3.                     Debug.Log ("Hit");
    4.                     hit.transform.GetComponent<PhotonView> ().RPC ("Damage", PhotonTargets.AllBuffered, damage);
    5.                 }
    6.  
    7.                 Debug.Log (hit.transform.name);
    8. }

    Health script:
    Code (CSharp):
    1. [PunRPC]
    2. public void Damage(float dmg){
    3.     Debug.Log ("Damaged");
    4.     health -= dmg;
    5. }
    6.  
    7. void OnGUI(){
    8. GUI.Box(newRect(10,10,100,30),"Health:"+health);
    9. }

    My player is tagged Player but whenever I shoot, it doesn't take damage. In my shoot script where I debug.log whatever I shoot, it does say the player so I am shooting the player but not taking damage.

    And also the part where I debug the words "Hit" and "Damaged", that doesn't show in the console too.
     
  2. Moddwyn

    Moddwyn

    Joined:
    Jan 27, 2016
    Posts:
    49
  3. Moddwyn

    Moddwyn

    Joined:
    Jan 27, 2016
    Posts:
    49
    please?
     
  4. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
    What does it print exactly at the "Debug.Log(hit.transform.name);" ?

    If it prints something at hit.transform.name, but not at "Hit" then it means you are hitting something, however, whatever you are hitting, is not tagged as player.

    Perhaps your collider is a component of an object that is not tagged as "Player".

    Screenshots from unity editor, where the correct gameobject with the collider are shown, would be helpful.
     
  5. Unknownperson123

    Unknownperson123

    Joined:
    Oct 27, 2021
    Posts:
    5
    use hit.collider.gameObject.tag instead