- Home /
How to make button whats multiple buys, like in clicker( 1,10 ,100)
Hi! I try to create a button what be miltiple buys items. Problem with that script is cost which multiply every time when i click on button and then i buy it, its reset to normal price. Should i put this code to the script with Items?
using System.Collections; using System.Collections.Generic; using System.Globalization; using UnityEngine; using UnityEngine.UI;
public class MultiplayerButton : MonoBehaviour { public Button multi; public Text x;
void Start()
{
multi.onClick.RemoveAllListeners();
multi.onClick.AddListener(buy10);
}
public void buy1()
{
x.text = "x1";
GlobalGuns.gunsValue = GlobalGuns.gunsValue;
GlobalGuns.gunsPerSec = GlobalGuns.gunsPerSec;
multi.onClick.RemoveAllListeners();
multi.onClick.AddListener(buy10);
}
public void buy10()
{
x.text = "x10";
GlobalGuns.gunsValue = 10 * GlobalGuns.gunsValue;
GlobalGuns.gunsPerSec = 10 * GlobalGuns.gunsPerSec;
multi.onClick.RemoveAllListeners();
multi.onClick.AddListener(buy100);
}
public void buy100()
{
x.text = "x100";
GlobalGuns.gunsValue = 100 * GlobalGuns.gunsValue;
GlobalGuns.gunsPerSec = 100 * GlobalGuns.gunsPerSec;
multi.onClick.RemoveAllListeners();
multi.onClick.AddListener(buy1);
}
}
Strangely, I recently answered a very similar question - how to make one button change option after each click. See if this helps you:
Your answer
Follow this Question
Related Questions
How do I make my player jump on click on the button? 3 Answers
How to use Button as Cross Platform Input 0 Answers
How to make on/off-like gui-button? 3 Answers
Button position scaling weird 1 Answer
UI button in Panel not clickable 2 Answers