I made a code and an UI. However, when I clicked the button, the total somtimes will increased to 15678 from 0, or 2346 from 0. But I want it plus 1 or 5 only. How can I solve it?
Button buttonA, buttonB;
public int total
void Start()
{
total = 0;
var root = GetComponent<UIDocument>().rootVisualElement;
buttonA = root.Q<Button>("buttonA")
buttonB = root.Q<Button>("buttonB")
}
void Update()
{
buttonA.clicked += CountA;
buttonB.clicked += CountB;
}
void CountA()
{
Count(1)
}
void CountB()
{
Count(5)
}
void Count(int num)
{
total += num;
}