Page 1 of 1

Text color change back to original

Posted: Mon Apr 17, 2023 2:47 pm
by Ronia
Hi!

I made a custom Sequencer Comand to change 'Subtitle' and 'Response' texts. It changes the color properly, but when it continues to the next 'Dialogue Entry', the color change back to the original color. I don't know if I'm missing something or doing anything wrong.

Here are the scripts:

Custom Sequencer Comand

Code: Select all

using UnityEngine;
using System.Collections;
using PixelCrushers.DialogueSystem;

namespace PixelCrushers.DialogueSystem.SequencerCommands
{
    public class SequencerCommandChangeTextColor : SequencerCommand
    {
        string colorName;

        public void Awake()
        {
            colorName = GetParameter(0);

            ChangeTextColor.CTC.ChangeColor(colorName);

            Stop();
        }
    }

}
Change Text Color Script

Code: Select all


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

public class ChangeTextColor : MonoBehaviour
{
    public static ChangeTextColor CTC;

    [SerializeField] Text subtitleText;
    [SerializeField] Text[] responseTexts;
    [SerializeField] Color yellow;
    [SerializeField] Color pink;
    [SerializeField] Color green;

    void Awake()
    {
        CTC = this;
    }

    public void ChangeColor(string color)
    {
        switch(color)
        {
            case "yellow":
                ChangeText(yellow);
                break;
            case "pink":
                ChangeText(pink);
                break;
            case "green":
                ChangeText(green);
                break;
            case "white":
                ChangeText(Color.white);
                break;
            default:
                ChangeText(Color.white);
                break;
        }
    }

    private void ChangeText(Color color)
    {
        subtitleText.color = color;

        foreach(Text responseText in responseTexts)
        {
            responseText.color = color;
        }
    }
}
Thanks in advance!

Re: Text color change back to original

Posted: Mon Apr 17, 2023 3:14 pm
by Tony Li
Hi,

Untick the Standard UI Response Button's "Set Label Color".

Subtitle panels save their original text color. To change it, you'll need to make a subclass of StandardUISubtitlePanel and add a method to change the originalColor, such as:

Code: Select all

public class MySubtitlePanel : StandardUISubtitlePanel
{
    public void SetTextColor(Color color) 
    { 
        originalColor = color;
        subtitleText.color = color;
    }
}
Then call this method in your sequencer command.

Re: Text color change back to original

Posted: Mon Apr 17, 2023 5:30 pm
by Ronia
Thanks it worked perfectly! :)

Re: Text color change back to original

Posted: Mon Apr 17, 2023 6:47 pm
by Tony Li
Glad to help!