Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Weird behaviour from non-master client with PUN.

Discussion in 'Connected Games' started by II_Spoon_II, Nov 5, 2018.

  1. II_Spoon_II

    II_Spoon_II

    Joined:
    Jun 16, 2018
    Posts:
    131
    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:
    131
    Anyone please?
     
  3. II_Spoon_II

    II_Spoon_II

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