Question by
tyboxsmash · Mar 25 at 05:20 PM ·
unity 2dpublic variable
Syncing Variables From an Object to a Button
I am making a clicker game and I have a button to upgrade you're CPC. The upgrade will cost clicks/cookies, but all the money is stored in the Clicker. So that means the upgrade button thinks you have zero money.
Here is the code for the clicker button and the upgrade button. It's the same script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Game_Script : MonoBehaviour
{
public int Money;
public Text MoneyText;
public Text CostText;
public int ClickUpgrade;
public int ClickUPCost;
void Start()
{
ClickUpgrade = 1;
ClickUPCost = 100;
}
// Update is called once per frame
void Update()
{
MoneyText.text = "Money: " + Money.ToString ();
CostText.text = "Upgrade CPC For: " + ClickUPCost.ToString ();
}
void OnMouseDown()
{
Money += ClickUpgrade;
}
public void Exitgame()
{
Debug.Log("Quit");
Application.Quit();
}
public void CPCUP()
{
if (Money >= ClickUPCost)
{
Money -= ClickUPCost;
ClickUPCost += ClickUPCost / 6;
ClickUpgrade++;
}
else
{
Debug.Log("You have no money!");
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Clickable object that increases mana variable in second script 1 Answer
How to make a boss who can shot toward an object, while the boss can do motion like the Earth 1 Answer
,ball flying effect in 2D like 3D 1 Answer
Unity Gradle Build Error 2019.3.10f 0 Answers
Collectable things counts multiple times 0 Answers