- Home /
Question by
a52166609 · Dec 21, 2019 at 09:19 PM ·
scripting problembuttonscriptingbasics
Distinguishing multiple buttons inside one function,distinguishing clicked buttons inside the function
Hi, for some reason I have to apply only one function to various buttons. So I tried to insert this kind of code inside button function :
..and so on. But I'm keep failing and getting the message 'ArgumentException : Input Button buttonName1 is not setup.' It would be very thankful if you help me..! ,Hi, for some reason I have to apply only one function to various buttons. So I tried to insert this kind of code inside button function :if (Input.GetButtonDown("buttonName1")) { Debug.Log("1clicked"); }
if (Input.GetButtonDown("buttonName2")) { Debug.Log("2clicked"); }
..and so on. But I'm keep failing and getting the message 'ArgumentException : Input Button buttonName1 is not setup.' It would be very thankful if you help me..!if (Input.GetButtonDown("buttonName1")) { Debug.Log("1clicked"); }
if (Input.GetButtonDown("buttonName2")) { Debug.Log("2clicked"); }
Comment
Answer by lgarczyn · Dec 21, 2019 at 09:21 PM
Input.GetButtonDown is not for UI buttons, but for controller or keyboard buttons, that are associated with a name through the Input system.
Please read the Unity manual for buttons to know how to receive a UI event. It usually cannot be done from a single script.