Я делаю многопользовательскую игру, в которой у каждого есть золото или переменная бомба. Я хочу установить это с помощью настраиваемых свойств, но получаю ошибку нулевой ссылки:NullReferenceException: Object reference not set to an instance of an object
Вот мой код PlayerController:
public class PlayerController : MonoBehaviourPunCallbacks
{
public ExitGames.Client.Photon.Hashtable myCustomProperties = new ExitGames.Client.Photon.Hashtable();
public Rigidbody rb;
public Player player;
public int playerID;
public int[] goldArray = { 1, 2, 5, 10, 20, 30, 50, 75, 100 };
private void Start()
{
SetCustomProps();
Debug.Log(PhotonNetwork.LocalPlayer.CustomProperties);
}
/*private void OnTriggerEnter(Collider other)
{
if (Input.GetKeyDown("space"))
{
Debug.Log("space pressed!");
Destroy(other.gameObject);
//swapBomb(other);
}
}*/
/*private void swapBomb(Collider other)
{
}*/
public void SetCustomProps()
{
int gold = (int)PhotonNetwork.LocalPlayer.CustomProperties["Gold"]; //error
gold = goldArray[Random.Range(0, goldArray.Length)] * 10;
myCustomProperties.Add("Gold", gold);
bool bomb = (bool)PhotonNetwork.LocalPlayer.CustomProperties["Bomb"];
bomb = false;
myCustomProperties.Add("Bomb", bomb);
PhotonNetwork.LocalPlayer.SetCustomProperties(myCustomProperties); //error
}
}
PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "PhotonPlayer"), Vector3.zero, Quaternion.identity);
Кажется, я не назначал ViewID, куда мне его назначать? - person Batuhan Koroglu   schedule 21.08.2020