我有两个按钮,一个用于Item1,一个用于Item2,但是Item2的文本确实更新,但是item1不是..
using UnityEngine;
使用System.Collections; 使用UnityEngine.UI;
公共类ItemScript:MonoBehaviour {
public Image icon;
public string ItemName;
public UnityEngine.UI.Text ItemNameInfo;
public UnityEngine.UI.Text Item1countInfo;
public UnityEngine.UI.Text Item1costInfo;
public UnityEngine.UI.Text Item2countInfo;
public UnityEngine.UI.Text Item2costInfo;
public Click Click;
public float Item1cost = 100;
public float Item2cost = 500;
public int Item1count;
public int Item2count;
public static int itemMPS;
private float Item1basecost;
private float Item2basecost;
public Button Button;
void Start()
{
Item1basecost = Item1cost;
Item2basecost = Item2cost;
}
void Update()
{
Item1countInfo.text = Item1count + "";
Item2countInfo.text = Item2count + "";
Item1costInfo.text = "Cost: " + Mathf.Round(Item1cost);
Item2costInfo.text = "Cost: " + Mathf.Round(Item2cost);
}
public void Item1()
{
if(Click.money >= Item1cost)
{
Click.money -= Item1cost;
Click.money = Mathf.Round(Click.money * 10) / 10;
itemMPS += 1;
Item1count += 1;
Item1cost = Item1basecost * Mathf.Pow(1.3f, Item1count);
Item1cost = Mathf.Round(Item1cost);
}
}
public void Item2()
{
if (Click.money >= Item2cost)
{
Click.money -= Item2cost;
Click.money = Mathf.Round(Click.money * 10) / 10;
itemMPS += 2;
Item2count += 1;
Item2cost = Item2basecost * Mathf.Pow(1.3f, Item2count);
Item2cost = Mathf.Round(Item2cost);
}
}
}
正如您在上面看到的,我有2个Onclick事件,但只有Item2更新其文本而Item 1没有..