Unity保存输入字段

时间:2018-06-19 14:56:18

标签: unity3d 2d nullreferenceexception

我正在制作2D平台游戏,希望用户输入的名称悬停在该平台上。 This is what the menu screen looks like

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class set_usernames : MonoBehaviour {

    public InputField name;
    public InputField second_name;

    private string Bader_input_name;
    private string Dwarf_input_name;

    public void updatename(string name){

    }
    public void setget()
    {
        //Debug.Log (name.text);
        Bader_input_name = name.text;
        Dwarf_input_name = second_name.text;

        //Application.loadedLevel("game");
        Debug.Log ("name was " + Bader_input_name);
        Debug.Log ("name was " + Dwarf_input_name);
        SceneManager.LoadScene ("map_select");
    }
}

This is the error message I get

1 个答案:

答案 0 :(得分:0)

基本上,这意味着您正在尝试访问未实例化的对象。我不知道您如何尝试访问输入,但是最简单的方法是在您的public中将两个UIController拖放到Unity中并访问输入的Text属性这样的对象:myInput.Text