Home > database >  The value no update , when using click event
The value no update , when using click event

Time:06-03

Why the value won't change, when I use 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
    }
}

and the inspector still show saveindex = 0; why

CodePudding user response:

Like KiynL said, both aren't events, they're methods. If you want to make something happen when you click or double click on some component, you have to select this component (Button, textBox, comboBox...) and go on to:

View > Properties > A yellow lightning button, there you'll have the possible events for the selected component.

Double click on the empty small textbox beside the event name and the method will be autogenerated, there is where you'll put your code.

This is a example of the event list (Photo - Imgur):

Events list

  • Related