PhotonNetwork is not working
Options
Tasos
✭
Hey, I am a Developer and I am using Unity!! Today I decided to make a multiplayer game...But when I tried to write my code it didn't work and Unity could not find PhotonNetwork.NickName Here is my code
using Photon.Pun;
using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Rpg.Menus
{
public class MainMenuInput : MonoBehaviour
{
[SerializeField] private TMP_InputField nameInputField = null;
[SerializeField] private Button continueButton = null;
private const string PlayerPrefsNameKey = "PlayerName";
private void Start() => SetUpInputField();
private void SetUpInputField()
{
if (!PlayerPrefs.HasKey(PlayerPrefsNameKey)) { return; }
string defaultName = PlayerPrefs.GetString(PlayerPrefsNameKey);
nameInputField.text = defaultName;
setPlayerName(defaultName);
}
private void setPlayerName(string name)
{
continueButton.interactable = !string.IsNullOrEmpty(name);
}
public void SavePlayerName()
{
string playerName = nameInputField.text;
PhotonNetwork.NickName = playerName;
PlayerPrefs.SetString(PlayerPrefsNameKey, playerName);
}
}
}
also, I use Photon Pun 2 Free Version
using Photon.Pun;
using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Rpg.Menus
{
public class MainMenuInput : MonoBehaviour
{
[SerializeField] private TMP_InputField nameInputField = null;
[SerializeField] private Button continueButton = null;
private const string PlayerPrefsNameKey = "PlayerName";
private void Start() => SetUpInputField();
private void SetUpInputField()
{
if (!PlayerPrefs.HasKey(PlayerPrefsNameKey)) { return; }
string defaultName = PlayerPrefs.GetString(PlayerPrefsNameKey);
nameInputField.text = defaultName;
setPlayerName(defaultName);
}
private void setPlayerName(string name)
{
continueButton.interactable = !string.IsNullOrEmpty(name);
}
public void SavePlayerName()
{
string playerName = nameInputField.text;
PhotonNetwork.NickName = playerName;
PlayerPrefs.SetString(PlayerPrefsNameKey, playerName);
}
}
}
also, I use Photon Pun 2 Free Version
0
Comments
-
Then something in your import got broken. PhotonNetwork.NickName does exist in the PUN 2 package.
Also, this can be a bug by Unity when you installed a certain Windows SDK:
"Reproducible with: 2018.4.23f1, 2019.4.0f1, 2020.1.0b11, 2020.2.0a13"
https://issuetracker.unity3d.com/issues/system-dot-net-dot-socket-objects-throw-argumentexception-in-il2cpp-after-installing-windows-sdk-20040