I can't set player names using input field (following tutorials in official web site)

Options
Hello All

I am new to Unity. Most probably I miss very basic point but for the last few days I am stuck at this point and can't see the mistake. I hope someone can show me where it is.

I use PhotonNetwork PUN for a multiplayer game and I follow the tutorials on the PUN web site.
https://doc.photonengine.com/en-us/...al/lobby-ui#creating_the_playernameinputfield

I follow the code written in the web site above, but still couldn't make it. Probably, I do something wrong with Input Field and On Value Changed().

Here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine.UI;

[RequireComponent(typeof(InputField))]
public class NicknameInputField : MonoBehaviour
 {
        #region Private Constants


	 // Store the PlayerPref Key to avoid typos
	 const string playerNamePrefKey = "PlayerName";


        #endregion


        #region MonoBehaviour CallBacks


	 /// <summary>
	 /// MonoBehaviour method called on GameObject by Unity during initialization phase.
	 /// </summary>
	 void Start () {


		 string defaultName = string.Empty;
		 InputField _inputField = this.GetComponent<InputField>();
		 if (_inputField!=null)
		 {
			 if (PlayerPrefs.HasKey(playerNamePrefKey))
			 {
				 defaultName = PlayerPrefs.GetString(playerNamePrefKey);
				 _inputField.text = defaultName;
			 }
		 }


		 PhotonNetwork.NickName =  defaultName;
	 }


        #endregion


        #region Public Methods


	 /// <summary>
	 /// Sets the name of the player, and save it in the PlayerPrefs for future sessions.
	 /// </summary>
	 /// <param name="value">The name of the Player</param>
	 public void SetPlayerName(string value)
	 {
		 // #Important
		 if (string.IsNullOrEmpty(value))
		 {
			 Debug.LogError("Player Name is null or empty");
			 return;
		 }
		 PhotonNetwork.NickName = value;


		 PlayerPrefs.SetString(playerNamePrefKey,value);
	 }


        #endregion
 }


I put input field object to On Value Changed () and choose SetPlayerNickName from the dropdown menu. (as i see in the web, there should be dynamic function section, but i can't see such section in the drop down).

Also i opened the demo scene imported with PUN. It is working in the demo scene but when i check the input field function part seems missing. I am really confused.
this image below is from demo scene of the tutorial.


basically i attach my script to inputfield object-->put inputfield object into the On Value Changed() in the inputfield object. and select function from the drop down. dropdown menu seems like this.


Can somebody show me where is my mistake please?

Comments

  • Ofi
    Options
    I have the same problem if someone can help us please tell me becose i can't continue with the tutorial right now.
  • Ofi
    Options
    I already fixed it, you need to use the method SetPlayerNickName WITHOUT parenthesees, There are two methods on the NicknameInputField, and is the one without the parenthesees "(string)".