I have a text box that fades in and out and changes colour depending on the animation, this works well enough, but the text doesn't change when i tell it to. I tried some other Stack answers, but they didn't work. Below is the script that contains the code that SHOULD change the text. I have been on this for ages and my brain hurts, mostly because of the animation (parameters and transitions mostly).
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();
}
}
}
You assign a string to PlankText.text
twice in all the script, once inside if (StonesFallen && IceFallen)
and once inside if (CompletedAnim1)
.
Problem is that you always assign to it the string "Drop All Ice"
, the first time using the string, and the second time using NewText
, which contains the same string.
And it can't be that NewText
changes its value outside the script, because it's private
, unless you cut out part of the class in your post.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.