good morning everyone i’m new to unity and programming, i’m creating a 2d block style game for mobile devices. In the game i would like to add the possibility that when i click play to play i get some coins deducted are there any tutorials that show how to make this type of buttons?
here is what you want
void Start()
{
UpdateCoinText();
playButton.onClick.AddListener(Play); // Add listener to button
}
void Play()
{
if (coins >= costToPlay)
{
coins -= costToPlay; // Deduct coins
UpdateCoinText();
// logic to start the game here
}
else
{
// show a no enough coins message
}
}
void UpdateCoinText()
{
coinText.text = "Coins: " + coins.ToString();
}
}