I’m trying to get the button to take the cost of the item away from the money the player has but this doesn’t seem to work. I’m new here so it may be extremely obvious but if you can fix it please explain what I did wrong if you can
thanks
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour {
public Texture btnTexture;
//START ITEM LIST
public float spoonDropsPerSecond = 1f;
public float spoonCost = 5000f;
//END ITEM LIST
public float startingDrops = 10f;
public float dropsCount = 0f;
bool menuOpen;
public float dropsPerSecond;
public float dropsMultiplier;
public float totalDropsPerSecond;
// Use this for initialization
void Start () {
Screen.showCursor = false;
dropsCount = startingDrops;
menuOpen = false;
dropsPerSecond ++;
}
// Update is called once per frame
void Update () {
totalDropsPerSecond = dropsPerSecond * (1 + dropsMultiplier);
dropsCount = dropsCount + totalDropsPerSecond * (Time.deltaTime * 1);
//remove before release
if (Input.GetKeyDown (KeyCode.Z)) {
dropsCount = 1000000f;
}
if (Input.GetKeyUp (KeyCode.Tab)) {
if (menuOpen == false) {
menuOpen = true;
Screen.showCursor = true;
}
else if (menuOpen == true) {
menuOpen = false;
Screen.showCursor = false;
}
}
//this is how I am displaying larger number but I removed some of the code
if (dropsCount < 1000) {
guiText.text = "Drops: " + dropsCount.ToString ("F0") + " DPS: " + dropsPerSecond.ToString("F0") + " Multiplier: x" + dropsMultiplier.ToString("F0") + " Total DPS " + totalDropsPerSecond.ToString("F0");
}
if(Input.GetKeyDown(KeyCode.Escape)){
Application.Quit();
}
}
void OnGUI(){
if (menuOpen == true) {
GUI.Box(new Rect( 0, 0, 900, 25),"Instructions: Press the corrosponding key to buy one for the price stated. To access lower levels you must purchase the upgrade at the end of the level");
if (GUI.Button (new Rect ( 20, 70, 220, 25), "test spoon click")){
if ( dropsCount >= spoonCost){
Debug.Log("this works");
dropsCount = dropsCount - spoonCost;
dropsPerSecond = dropsPerSecond + spoonDropsPerSecond;
}
}
//GUI.Box(new Rect( 20, 70, 220, 25),"Spoon, 5000 Drops, +1 DPS");
}
}
}