Search Unity

Third Party Weird behaviour from non-master client with PUN.

Discussion in 'Multiplayer' started by II_Spoon_II, Nov 5, 2018.

  1. II_Spoon_II

    II_Spoon_II

    Joined:
    Jun 16, 2018
    Posts:
    180
    Hello ^^

    I have the following script attached to each tower in my game, it works as I intend (the code still not very clean still)
    Code (CSharp):
    1. public class TowerSelection :Photon.MonoBehaviour/*, IPunObservable*/
    2.     {
    3.         public MeshRenderer MR;
    4.         public GameObject[] units;
    5.         public int NrOfUnits;
    6.         MyPlayerManager GM;
    7.         Camera cam;
    8.  
    9.         // Use this for initialization
    10.         void Start()
    11.         {
    12.             MR = gameObject.GetComponent<MeshRenderer>();
    13.             GameObject TGameman = GameObject.Find("GM");
    14.             GameManager gameManager = TGameman.GetComponent<GameManager>();
    15.  
    16.             if (PhotonNetwork.isMasterClient)
    17.             {
    18.                 cam = gameManager.cam1;
    19.             }
    20.             else
    21.             {
    22.                 cam = gameManager.cam2;
    23.             }
    24.  
    25.              GM = cam.GetComponent<MyPlayerManager>();
    26.         }
    27.         void OnMouseDown()
    28.         {
    29.             if (GM.BaseTower == null)
    30.             {
    31.                 if (cam.tag == gameObject.tag) {
    32.  
    33.                 GM.BaseTower = gameObject;
    34.  
    35.                 GM.baseT = gameObject;
    36.                 }
    37.             }
    38.             if (gameObject != GM.BaseTower )
    39.             {
    40.                 GM.TargetTower = gameObject;
    41.                 GM.TTS = gameObject;
    42.                 StartCoroutine(Instantiator());
    43.  
    44.                 GM.BaseTower = null;
    45.                 GM.TargetTower = null;  
    46.             }
    47.             else if (GM.BaseTower != null && GM.TargetTower != null)
    48.             {
    49.                 GM.BaseTower = null;
    50.                 GM.TargetTower = null;
    51.             }    
    52.         }
    Each player has his own camera ( 1 v 1) and the "my player maanger" class I am accessing is attached to both the cameras.
    Code (CSharp):
    1. public class MyPlayerManager : Photon.MonoBehaviour
    2.     {
    3.  
    4.         public GameObject BaseTower;
    5.         public GameObject TargetTower;
    6.         public GameObject TTS;
    7.         public GameObject[] units;
    8.         public GameObject baseT;
    9.  
    10.  
    11.         // Use this for initialization
    12.         void Start()
    13.         {
    14.             foreach(GameObject Unit in units)
    15.             {
    16.                 Unit.tag = gameObject.tag;
    17.             }
    18.      
    19.         }
    20.  
    21.        
    22.     }
    How you guys see it's just simple scripts, the weird problem I am facing is that when the non master client selects a base tower A1 and a target tower B1 (the units go from the base one to the target one), if he wants to reselect the A1 tower again later, the BaseTower stays null and A1 goes to TragetTower, which is really weird cause it works perfectly on the master client.
     
  2. II_Spoon_II

    II_Spoon_II

    Joined:
    Jun 16, 2018
    Posts:
    180
    Anyone please?
     
  3. II_Spoon_II

    II_Spoon_II

    Joined:
    Jun 16, 2018
    Posts:
    180
    no one has any idea?