【问题标题】:Unity saving inputfield统一保存输入框
【发布时间】:2018-11-28 14:17:50
【问题描述】:

我正在制作一个 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

【问题讨论】:

标签: unity3d 2d nullreferenceexception


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    • 2021-11-27
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    • 2019-07-26
    • 2018-03-18
    相关资源
    最近更新 更多