Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Can someone help me with this code error } type or namespace definition or end-of-file expected

Discussion in 'Multiplayer' started by BlobbyGames, Dec 5, 2021.

  1. BlobbyGames

    BlobbyGames

    Joined:
    Dec 20, 2020
    Posts:
    2
    i cant fix this so can someone help?
    Code (CSharp):
    1. using Photon.Pun;
    2. using UnityEngine;
    3. using TMPro;
    4. using UnityEngine.UI;
    5.  
    6.    public class PlayerNameInput : MonoBehaviour
    7.    {
    8.         [SerializeField] private TMP_InputField nameInputField = null;
    9.         [SerializeField] private Button continueButton = null;
    10.  
    11.         private const string PlayerPrefsNameKey = "PlayerName";
    12.  
    13.  
    14.         private void Start() => SetUpInputField();
    15.  
    16.  
    17.         private void SetupInputField()
    18.         {
    19.             if(!PlayerPrefs.HasKey(PlayerPrefsNameKey))  { return; }
    20.  
    21.             string defaultName = PlayerPrefs.GetString(PlayerPrefsNameKey);
    22.  
    23.             nameInputField.text = defaultName;
    24.  
    25.             SetPlayerName(defaultName);
    26.         }
    27.  
    28.  
    29.         private void SetPlayerName(string name)
    30.         {
    31.             continueButton.interactable = !string.IsNullOrEmpty(name);
    32.         }
    33.  
    34.         public void SavePlayerName()
    35.         {
    36.             string playerName = nameInputField.text;
    37.  
    38.             PhotonNetwork.NickName = playerName;
    39.  
    40.             PlayerPrefs.SetString(PlayerPrefsNameKey, playerName);
    41.         }
    42.  
    43.     }
    44.  
    45. }
    the error is coming from the last } so can anyone help?
     
  2. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,663
    Remove it since there's no need for it to be there.
     
  3. BlobbyGames

    BlobbyGames

    Joined:
    Dec 20, 2020
    Posts:
    2
    turns out i dont even need the script whoops! but if i did it it will give errors