Forum rules - please read before posting.

Set background color

edited March 6 in Technical Q&A

Hi every one. I would like to change the background color of the name of the speaking character in my dialogue window. The color should be the one defined in the speech text color. How can i do that?
Here how my dialog menu is : https://ibb.co/fdC89V17

Thx

Comments

  • By default, Label elements will set the colour of your Text components - not the background.

    If you want to alter the background, use scripting attached to the UI prefab:

    using UnityEngine.UI;
    using UnityEngine;
    using AC;
    
    public class SetBackgroundSpeechColor : MonoBehaviour
    {
    
        public Image image;
        public Canvas canvas;
    
        void OnEnable ()
        {
            var menu = KickStarter.playerMenus.GetMenuWithCanvas (canvas);
            var speech = menu.speech;
            if (speech != null)
            {
                image.color = speech.GetColor ();
            }
        }
    
    }
    
  • edited March 6

    So i have to set my Dialogue menu to Unity UI prefab?
    Here how my menu is set : https://ibb.co/zh7v90Xs
    https://ibb.co/279Vnz30

    I have an error after creat the script :

    Assets\DetectiveDesforge\Scripts\SetBackgroundSpeechColor.cs(17,34): error CS1061: 'Speech' does not contain a definition for 'GetColor' and no accessible extension method 'GetColor' accepting a first argument of type 'Speech' could be found (are you missing a using directive or an assembly reference?)

  • Yes, you'll need to use Unity UI.

    My mistake - GetColour, not GetColor.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.