如何解决我在unity 2d中收到此错误“对象引用未设置为对象convert.Awake的实例”
我正在尝试从文本框中输入值,然后从第一个下拉列表和第二个下拉列表中选择值以在第二个只读文本框中显示所需的值。假设这用于转换不同类型长度的值。我把唤醒功能放在开始拉下拉默认值。所以我收到这个错误“对象引用未设置到对象 convert.Awake() 的实例”。请告诉我我怎么做以及我做错了什么?我知道这很容易,但我是新手:(
public InputField fromValue;
public InputField tovalue;
public UnityEngine.UI.Dropdown from = null;
public UnityEngine.UI.Dropdown to = null;
public UnityEngine.UI.Button convertButton = null;
// Start is called before the first frame update
void Start()
{
from = GetComponent<UnityEngine.UI.Dropdown>();
to = GetComponent<UnityEngine.UI.Dropdown>();
Awake();
}
// Update is called once per frame
void Update()
{
}
public void Awake()
{
convertbutton.onClick.AddListener(() => { CompareValues(); });
from.onValueChanged.AddListener((newValueOnLeft)
=>
{ CompareValuesWithTo(newValueOnLeft); });
to.onValueChanged.AddListener((newValueOnRight)
=>
{ CompareValuesWithFrom(newValueOnRight); });
}
public void CompareValues()
{
int rightValue = from.value;
int leftValue = to.value;
if (leftValue == rightValue)
{
tovalue.text = "Match " + "f: " + from.options[from.value].text + "t: " + to.options[to.value].text;
//Debug.Log("Match!");
}
else
{
tovalue.text = "No Match";
//Debug.Log("Not Match!");
}
}
public void CompareValuesWithTo(int newValueOnLeft)
{
int rightValue = to.value;
if (newValueOnLeft == rightValue)
{
Debug.Log("Match!");
tovalue.text = "Match " + "f: " + from.options[from.value].text + "t: " + to.options[to.value].text;
}
else
{
Debug.Log("Not Match!");
tovalue.text = "No Match";
}
}
public void CompareValuesWithFrom(int newValueOnRight)
{
int leftValue = from.value;
if (leftValue == newValueOnRight)
{
Debug.Log("Match!");
tovalue.text = "Match " + "f: " + from.options[from.value].text + "t: " + to.options[to.value].text;
}
else
{
Debug.Log("Not Match!");
tovalue.text = "No Match";
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。