I have 1 script attached to my player for dehydration. That when the player is not drinking water he should dehydrate now i have one text ui for number of bottle player currently havw have and one slider how showing how much water is present in his body. I am developing this for android. So when i press g my charcter drinks water. Now i just create a ui button named drink water. In script I added input.getbuttondown (“drinkwater”) but when i play the game the text ui which show how many bottles player currently have it shows 0 and that slider also shows 0. Now when i again change that button to g everything works normal. But i can not use a g button on android please help.
Input.GetButtonDown, as detailed in the API documentation, is for use with the Input system, not the UI.
To do what you want to do, make a public method in your script. Then find the UI button and scroll down in the Inspector to the “On Click()” section. Whatever object has your script attached to it, drag to the box on the left portion. Then find your method in the dropdown on the right and select that. More details here.
There are ways to do this all from within your code, but this is the simplest way to set it up, and works for me for most cases.
I’ll give it a go
So should I just remove the statement Input.GetKeyDown if I just want to use the button
Yeah. UI and Input are two very different things.
Have you gone through those tutorials yet?
Unity tutorials yeah
@Schneider21 By the way thanks