【发布时间】:2016-03-24 13:22:03
【问题描述】:
我在 CANVAS 1 中有一个名为 Total Points Text 的 UI 文本,在 CANVAS 2 中有一个图像。 一个按钮组件附加到图像上,因此当它被触摸时,图像会被破坏并应该更改 Total Points Text 中的文本。
问题是,调用 onClick of Image 的函数被调用,但 Total Points Text 中的 Text 没有改变。
奇怪的是,当我移动将文本更改为图像的 Start() 的行时,文本确实发生了变化...... 另一个奇怪的事情是,我确实用我的目标脚本(附加到我的角色的那个)更改了总点数文本几次,它工作正常。也许问题来自按钮-onClick?
这是我的代码:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class twohundredPTSScript : MonoBehaviour
{
public Image TWOHundredpointsImage;
public Text TotalPointsText;
public void Purchase200()
{
int totalpoints = ballscript.TotalPoints;
if(totalpoints >= 200)
{
Destroy(TWOHundredpointsImage); // CALLED
totalpoints = totalpoints - 200; // CALLED
Debug.Log(totalpoints); // CALLED
Debug.Log("Item bought !"); // CALLED
TotalPointsText.text = "Total points: " + totalpoints.ToString(); // THIS ISN'T CALLED OR ISN'T WORKING.
}
else
{
Debug.Log("Not enough points !");
}
ballscript.TotalPoints = totalpoints;
}
}
【问题讨论】:
标签: c# user-interface button text unity3d