Search Unity

Question Maybe a Bug? CustomProprerties

Discussion in 'Multiplayer' started by caiowgcw, Dec 1, 2020.

  1. caiowgcw

    caiowgcw

    Joined:
    Jun 5, 2019
    Posts:
    11


    Is working perfectly, but getting this error when i get on slots.
    Should i get worries about that?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Photon.Pun;
    5. using TMPro;
    6. using System.IO;
    7. using Photon.Realtime;
    8. using Hashtable = ExitGames.Client.Photon.Hashtable;
    9.  
    10. public class SpawnManager : MonoBehaviourPunCallbacks
    11. {
    12.     public static SpawnManager Instance;
    13.     private bool[] isSlotOccuped;
    14.  
    15.  
    16.     public Transform[] slots;
    17.     public GameObject[] slotsButtons;
    18.     public GameObject questionMenuButton;
    19.     public GameObject questionMenu;
    20.     public int slotsActual;
    21.     public int ready = 0;
    22.     public bool startQuestionTrigger = true;
    23.  
    24.     public void Awake()
    25.     {
    26.         if(SpawnManager.Instance == null)
    27.         {
    28.             SpawnManager.Instance = this;
    29.         }
    30.     }
    31.     public void Start()
    32.     {
    33.         isSlotOccuped = new bool[PhotonNetwork.PlayerList.Length];
    34.         ChangeSizeSlots();
    35.     }
    36.     public void ChangeSizeSlots()
    37.     {
    38.  
    39.         slotsActual = PhotonNetwork.PlayerList.Length;
    40.  
    41.         for (int i = 0; i < slotsActual; i++)
    42.         {
    43.             slotsButtons[i].SetActive(true);
    44.             isSlotOccuped[i] = false;
    45.  
    46.         }
    47.  
    48.     }
    49.  
    50.     void TakeSlot(int slotIndex)
    51.     {
    52.         if(isSlotOccuped[slotIndex] == false)
    53.         {
    54.             PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "Player"), SpawnManager.Instance.slots[slotIndex].position, Quaternion.identity);  
    55.         }
    56.         else
    57.         {
    58.             Debug.Log("Slot Occuped");
    59.         }    
    60.         PhotonNetwork.CurrentRoom.SetCustomProperties(new Hashtable() { { "Slot", slotIndex } });
    61.         isSlotOccuped[slotIndex] = true;      
    62.     }
    63.  
    64.     public override void OnRoomPropertiesUpdate(Hashtable propertisThatChanged)
    65.     {
    66.  
    67.         VerifySlot();
    68.         VeifyStartQuestion();
    69.  
    70.     }
    71.  
    72.  
    73.     void VerifySlot()
    74.     {
    75.         slotsButtons[(int)PhotonNetwork.CurrentRoom.CustomProperties["Slot"]].SetActive(false);
    76.         ready++;
    77.         if(ready == slotsActual)
    78.         {
    79.             questionMenuButton.SetActive(PhotonNetwork.IsMasterClient);
    80.         }
    81.      
    82.     }
    83.     public void StartQuestion(bool startIndex)
    84.     {
    85.         PhotonNetwork.CurrentRoom.SetCustomProperties(new Hashtable() { { "StartQuestion", startIndex } });
    86.      
    87.     }
    88.     public void VeifyStartQuestion()
    89.     {
    90.      
    91.         if(startQuestionTrigger == (bool)PhotonNetwork.CurrentRoom.CustomProperties["StartQuestion"])
    92.         {
    93.             OpenQuestionMenu();
    94.         }
    95.     }
    96.  
    97.     void OpenQuestionMenu()
    98.     {
    99.         questionMenu.SetActive(true);
    100.         PhotonNetwork.CurrentRoom.SetCustomProperties(new Hashtable() { { "StartQuestion", false } });
    101.     }
    102.  
    103.  
    104.  
    105. }
    106.  
     
    Last edited: Dec 1, 2020