值没有更新,当使用点击事件时
The value no update , when using click event
为什么我使用点击事件时,值不会改变?
public class Custom : MonoBehaviour
{
public int saveindex;
public void Oneclick(int buttonindex)
{
saveindex = buttonindex;
Debug.Log(saveindex); // Show buttonindex
}
public void Twoclick(int buttonindex)
{
Debug.Log(saveindex); // Show 0
}
}
并且检查器仍然显示 saveindex = 0;为什么
如KiynL所说,两者都不是事件,而是方法。
如果你想在点击或双击某个组件时发生某些事情,你必须 select 这个组件 (Button, textBox, comboBox...) 然后继续至:
View > Properties > A yellow lightning button, there you'll have the possible events for the selected component.
双击事件名称旁边的空白小文本框,方法 将自动生成,您可以在此处放置代码。
这是事件列表的示例(图片 - Imgur):
Events list
为什么我使用点击事件时,值不会改变?
public class Custom : MonoBehaviour
{
public int saveindex;
public void Oneclick(int buttonindex)
{
saveindex = buttonindex;
Debug.Log(saveindex); // Show buttonindex
}
public void Twoclick(int buttonindex)
{
Debug.Log(saveindex); // Show 0
}
}
并且检查器仍然显示 saveindex = 0;为什么
如KiynL所说,两者都不是事件,而是方法。 如果你想在点击或双击某个组件时发生某些事情,你必须 select 这个组件 (Button, textBox, comboBox...) 然后继续至:
View > Properties > A yellow lightning button, there you'll have the possible events for the selected component.
双击事件名称旁边的空白小文本框,方法 将自动生成,您可以在此处放置代码。
这是事件列表的示例(图片 - Imgur):
Events list