- Home /
Photon Combat script does not work
I am using photon for my game and I have one player gameobject but it does not work
Combat script: using UnityEngine; using System.Collections; using UnityEngine.UI;
public class Combat : MonoBehaviour { public float Health = 100; private float MinHealth = 0; private float MaxHealth = 100;
 public Slider slider;
 public virtual void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.isWriting)
     {
         stream.SendNext(Health);
     } else if (stream.isReading)
     {
         Health = (float)stream.ReceiveNext();
     }
 }
 [PunRPC]
 public void Damage()
 {
     Health -= 10;
     slider.value = Health;
 }
}
The script which I use to apply damage:
using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon;
public class WhichCollider : PunBehaviour { public GameObject player; public Collider2D coll;
 private bool CanHit;
 private bool CanHit2;
 
 private void OnTriggerEnter2D(Collider2D collision)
 {
     coll = collision;
     CanHit = true;
 }
 private void OnTriggerExit2D(Collider2D collision)
 {
     CanHit = false;
 }
 private void Update()
 {
     if (CanHit == true)
     {
         if (player.GetComponent<AnimController>().Flipped == true)
         {
             if (gameObject.name == "Collider1")
             {
                 if (player.GetComponent<AnimController>().WaitForHit == true)
                 {
                     if (coll.gameObject.CompareTag("Player"))
                     {
                         if (CanHit2 == false)
                         {
                             CanHit2 = true;
                             print("Links");
                             StartCoroutine(SetCanHit());
                         }
                     }
                 }
             }
         }
         if (player.GetComponent<AnimController>().Flipped == false)
         {
             if (gameObject.name == "Collider2")
             {
                 if (player.GetComponent<AnimController>().WaitForHit == true)
                 {
                     if (coll.gameObject.CompareTag("Player"))
                     {
                         if (CanHit2 == false)
                         {
                             CanHit2 = true;
                             print("Rechts");
                             StartCoroutine(SetCanHit());
                         }
                     }
                 }
             }
         }
     }
 }
 IEnumerator SetCanHit()
 {
     yield return new WaitForSeconds(0.3f);
     photonView.RPC("Damage", PhotonTargets.All);
     CanHit2 = false;
 }
}
Please do not open duplicate questions.... Original question can be found here...
Your answer
 
 
             Follow this Question
Related Questions
My Photon health script doesnt work 2 Answers
Decrase value on collision C# 2 Answers
PhotonUnityNetworking UnityException 0 Answers
PUN - Choose random Hero for player 0 Answers
My player HP are get decreased from several GameObjects that has is Trigger on 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                