Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何检查播放器是否在输入字段中写入了内容?_C#_Unity3d - Fatal编程技术网

C# 如何检查播放器是否在输入字段中写入了内容?

C# 如何检查播放器是否在输入字段中写入了内容?,c#,unity3d,C#,Unity3d,我需要玩家先写下他的名字,然后点击unity预先制作的按钮 public void GetNextScene() { 如果(InputPlayerName!=null) { _playerName=输入playerName.text; 场景管理器。加载场景(NextScene); } 其他的 { Log(“请先写下你的名字”); } } 您可能希望在播放机更改输入字段中的文本时动态启用和禁用按钮 如果使用常规输入字段和TextMesh Pro,则必须使用onValueChanged事件 示例来自

我需要玩家先写下他的名字,然后点击unity预先制作的按钮

public void GetNextScene()
{
如果(InputPlayerName!=null)
{
_playerName=输入playerName.text;
场景管理器。加载场景(NextScene);
}
其他的
{
Log(“请先写下你的名字”);
}
}

您可能希望在播放机更改输入字段中的文本时动态启用和禁用按钮

如果使用常规输入字段和TextMesh Pro,则必须使用onValueChanged事件

示例来自:


为什么我总是要找到答案,当我在这里提出我的问题。。。我刚刚做了if(InputPlayerName.text!=“输入名称”)为我解决了这个问题。你可以删除这个问题,对吗?或者您可以回答自己的问题,然后接受答案
如果(InputPlayerName!=null)
检查输入字段是否为null,而不是其内容。Draco18s我不知道如何做。。。。。
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.

public class Example : MonoBehaviour
{
    public InputField mainInputField;

    public void Start()
    {
        //Adds a listener to the main input field and invokes a method when the value changes.
        mainInputField.onValueChanged.AddListener(delegate {ValueChangeCheck(); });
    }

    // Invoked when the value of the text field changes.
    public void ValueChangeCheck()
    {
        Debug.Log("Value Changed");
    }
}