Text color change back to original

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Ronia
Posts: 5
Joined: Thu Mar 04, 2021 7:17 am

Text color change back to original

Post 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!
User avatar
Tony Li
Posts: 22152
Joined: Thu Jul 18, 2013 1:27 pm

Re: Text color change back to original

Post 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.
Ronia
Posts: 5
Joined: Thu Mar 04, 2021 7:17 am

Re: Text color change back to original

Post by Ronia »

Thanks it worked perfectly! :)
User avatar
Tony Li
Posts: 22152
Joined: Thu Jul 18, 2013 1:27 pm

Re: Text color change back to original

Post by Tony Li »

Glad to help!
Post Reply