繁体   English   中英

Unity C#文本未更改

[英]Unity C# text not changing

我有一个文本框,它会根据动画的不同而逐渐淡入和淡出,并改变颜色,效果很好,但是当我告诉它时,文本不会改变。 我尝试了其他一些Stack答案,但是它们没有用。 以下是包含应更改文本的代码的脚本。 我已经有很长一段时间了,我的大脑受伤,主要是因为动画(主要是参数和过渡)。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using UnityEngine.UI;

public class Objectives : MonoBehaviour {
#region Variables
public bool CompletedAnim1;
public bool StonesFallen;
public bool IceFallen;
public Objective ObjectiveRef;
public Text PlankText;
public AnimController AnimContRef;
public TextController TextContRef;
string NewText;
#endregion Variables

// Use this for initialization
void Start () {
    CompletedAnim1 = false;
    NewText = "Drop All Ice";
    PlankText.SetAllDirty();
}

// Update is called once per frame
void Update () {
    if (StonesFallen)
        ObjectiveRef.ObjectiveCompleted = true;

    if (StonesFallen && IceFallen)
    {
        PlankText.text = "Drop All Ice";
        ObjectiveRef.ObjectiveCompleted = false;
        AnimContRef.SetTriggerParameter("FadeIn");
        Debug.Log("Ice and Stones Fallen");
    }

    if (CompletedAnim1)
    {
        PlankText.text = NewText;
        Debug.Log("CompletedAnim1");
        Debug.Log(PlankText.text);
        PlankText.SetAllDirty();
    }
}


}

您在所有脚本中两次将字符串分配给PlankText.text ,一次在if (StonesFallen && IceFallen) ,一次在if (CompletedAnim1)

问题是,您始终将字符串"Drop All Ice"分配给它,第一次使用该字符串,第二次使用NewText ,其中包含相同的字符串。

而且, NewText不能在脚本之外更改其值,因为它是private ,除非您在帖子中删除了该类的一部分。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM