I am implementing a feature that my button should only spawn a limited amount of objects.
I put a counter on the button so that it shows how many clicks are remaining until it reaches 0.
Then the count stops but the button is still active.
How can I disable the button after the count reaches 0, so that one can not spawn anymore objects.
I am using the code below to reduce the count.
Thanks for the help.
private TMP_Text _spawn;
private int _spawnAmount;
void Start()
{
_spawnAmount = 2;
_spawn = GetComponent<TMP_Text>();
}
void Update()
{
_spawn.text = _spawnAmount.ToString();
}
public void ReduceSpawnAmount()
{
if (_spawnAmount > 0)
{
_spawnAmount--;
}
else
{
return;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…