c# - 如何检查玩家是否在输入字段中写了一些东西?
问题描述
我需要玩家先写下他的名字,然后再点击统一的预制按钮上的播放。
public void GetNextScene()
{
if (InputPlayerName != null)
{
_playerName = InputPlayerName.text;
SceneManager.LoadScene(NextScene);
}
else
{
Debug.Log("Please, write your name first");
}
}
解决方案
您可能希望在播放器更改输入字段中的文本时动态启用和禁用按钮。
您必须使用 onValueChanged 事件,如果您使用常规输入字段,则为该事件,如果您使用 TextMesh Pro,则为该事件。
这里的例子:
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");
}
}
推荐阅读
- postgresql - Postgres:使用提取大小进行事务隔离
- oracle11g - oracle 中是否有临时可用的内置表或表空间?
- javascript - 无法在所有画布上上传图像
- android - RecyclerView 将图像设置在错误的位置
- javascript - 使用 VSCode 将常量重构为惰性常量
- arrays - 如何在反应表的行中呈现数组数据
- java - RestTemplate 与自定义 ConnectionPool?
- angular - 带有远程访问的角度生产?
- kubernetes - Kubernetes Cronjob 在 GKE 中使用临时卷
- hibernate-mapping - NotNavigableException 原因