I am creating an idle game, and in this code I am trying to make it so the button starts out noninteractable, but changes to interactable once the cost is reached. I’m new with this, so sorry if the answer is obvious. Here is the code in C#:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class UpgradeManager : MonoBehaviour {
public Click click;
public UnityEngine.UI.Text itemInfo;
public float cost;
public Button UpgradeButton;
public int count = 0;
public int clickPower;
public string itemName;
private float baseCost;
void Start() {
baseCost = cost;
UpgradeButton.interactable = false;
}
void Update() {
itemInfo.text = itemName + "
Cost: " + cost + "
Click Power: +" + clickPower;
}
public void PurchasedUpgrade() {
if (click.food >= cost) {
click.food -= cost;
count += 1;
click.foodperclick += clickPower;
UpgradeButton.interactable = true;
}
}
}
Here is a pic if it helps: