Hey guys,
now because im a newbie to unity programming i have a question:
How can i add a tap countdown ?
Just to explain I m want to do a tapping game where I have to click a button 200 times to get some cash. So how can I do it so if tap the button once the counter goes from 200 to 199 ?
Let’s assume you have your countdown method written in a script called “Countdown.cs”, which is a component of a GameObject “CountdownGO”. Somethign like this.
public class Countdown : MonoBehaviour {
public int Counter{get;private set;}
private const int startValue=200;
void Start ()
{
Counter=startValue;
}
public void CountOneDown()
{
Counter--;
}
}
Then go to GameObject–>UI → Button. Click on the game Object and in the inspector in the Button component you find the OnClick() field (.s picture).
Now click on +, drag the gameObject CountDownGO on it, choose the CountOneDown()
Method from the drop down menue and you are ready to go.
If you want to do this from script during runtime, you have to use Button.onClick.AddListener