I’m trying to take in the player name using an InputField then I want to display it on the next scene.
I’ve tried numerous times using the code listed below and other methods but an unassigned reference exception seems to be preventing my success.
Can someone provide an alternative solution that can allow me to pass the Input field information to the next scene and display it?
Input Player Name
using UnityEngine;
using UnityEngine.UI;
public class nameSelection : MonoBehaviour
{
public static nameSelection askName;
public InputField inputField;
public string userName;
private void Awake()
{
if (askName == null)
{
askName = this;
DontDestroyOnLoad(gameObject);
}
else Destroy(gameObject);
}
private void Update()
{
if (userName != inputField.text)
{
userName = inputField.text;
}
}
}
Display Player Name on Next Scene
using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class GetName : MonoBehaviour
{
public GameObject textDisplay;
public void Awake()
{
textDisplay.GetComponent<Text>().text = nameSelection.askName.userName + "'s Score";
}
}
Thank You