Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Serialize Field Has a bunch of errors

Discussion in 'Scripting' started by ChipotleGod, Nov 13, 2020.

  1. ChipotleGod

    ChipotleGod

    Joined:
    Jul 20, 2020
    Posts:
    48
    Hello I am doing this code for names in my game and it keeps showing errors. I think its because of the Serialize
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerNameInput : MonoBehaviour
    6. {
    7.     public class PlayerNameInput:MonoBehaviour
    8.     {
    9.         [Header("UI")]
    10.         [SerializeField] private TMP_InputField nameInputField
    11.         [SerializeField]; private Button continueButton=null;
    12.        
    13.  
    14.         public static string DisplayName {get; private set;}
    15.        
    16.         private const string PlayerPrefsNameKey="PlayerName";
    17.  
    18.         private void Start() => SetUpInputField();
    19.  
    20.         private void SetUpInputField()
    21.     {
    22. if (!PlayerPrefs.HasKey(PlayerPrefsNameKey)) {return; }
    23.  
    24. string defaultName=PlayerPrefs.GetString(PlayerPrefsNameKey);
    25.  
    26. nameInputField.text=defaultName;
    27.  
    28. SetPlayerName(defaultName);
    29.     }
    30.     public void SetPlayerName(string name)
    31.     {
    32.         continueButton.interactable-!string.IsNullOrEmmpty(name);
    33.     }
    34.  
    35.  
    36.    public void SavePlayerName()
    37.    {
    38.      DisplayName-nameInputField.text;
    39.  
    40.      PlayerPrefs.SetString(PlayerPrfsNameKey, DisplayName);
    41.    
    42.       }
    43.  
    44.     }
    45.  
    46.    }
    47.  
    48.  
    49.  
    field but I dont know completely.
     

    Attached Files:

  2. BABIA_GameStudio

    BABIA_GameStudio

    Joined:
    Mar 31, 2020
    Posts:
    488
    In this bit of code:
    Code (csharp):
    1. [SerializeField] private TMP_InputField nameInputField
    2. [SerializeField]; private Button continueButton=null;
    On the first line you are missing a semi-colon after
    nameInputField
    and on the second line you have a semi-colon between
    [SerializeField]
    and
    private
     
    mopthrow likes this.
  3. ChipotleGod

    ChipotleGod

    Joined:
    Jul 20, 2020
    Posts:
    48
    Ok that fixed one thing thank you. But there is now this error
     
  4. ChipotleGod

    ChipotleGod

    Joined:
    Jul 20, 2020
    Posts:
    48
    Sorry here you go
     

    Attached Files:

  5. BABIA_GameStudio

    BABIA_GameStudio

    Joined:
    Mar 31, 2020
    Posts:
    488
    Then please show your updated code, as what is in the thread is now out of date if you made the previous changes.
     
  6. ChipotleGod

    ChipotleGod

    Joined:
    Jul 20, 2020
    Posts:
    48
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerNameInput : MonoBehaviour
    6. {
    7.     public class PlayerNameInput:MonoBehaviour
    8.     {
    9.         [Header("UI")]
    10.         [SerializeField] private TMP_InputField nameInputField;
    11.         [SerializeField]; private Button continueButton=null;
    12.        
    13.  
    14.         public static string DisplayName {get; private set;}
    15.        
    16.         private const string PlayerPrefsNameKey="PlayerName";
    17.  
    18.         private void Start() => SetUpInputField();
    19.  
    20.         private void SetUpInputField()
    21.     {
    22. if (!PlayerPrefs.HasKey(PlayerPrefsNameKey)) {return; }
    23.  
    24. string defaultName=PlayerPrefs.GetString(PlayerPrefsNameKey);
    25.  
    26. nameInputField.text=defaultName;
    27.  
    28. SetPlayerName(defaultName);
    29.     }
    30.     public void SetPlayerName(string name)
    31.     {
    32.         continueButton.interactable-!string.IsNullOrEmmpty(name);
    33.     }
    34.  
    35.  
    36.    public void SavePlayerName()
    37.    {
    38.      DisplayName-nameInputField.text;
    39.  
    40.      PlayerPrefs.SetString(PlayerPrfsNameKey, DisplayName);
    41.    
    42.       }
    43.  
    44.     }
    45.  
    46.    }
    47.  
    48.  
    49.  
     
  7. mopthrow

    mopthrow

    Joined:
    May 8, 2020
    Posts:
    343
    You forgot to remove the semi colon on line 11 that @BaBiAGameStudio pointed out in #2 ;)