Forum rules - please read before posting.

Save fontSize of object

Hi,

i want to have an option in menu to set bigger font size for my subtitles menu. That itself is simple. It's an Unity UI Prefab menu. I'm able to access the gameobject via AC.Menu.canvas and change the fontSize. How do i make this change saved in the save file?

Based on a tutorial i've created this script and attached it to the text object.

http://pasteall.org/1393854/csharp

After saving and loading the font size keeps unchanged. What am i missing?

Comments

  • edited November 2018

    Presumably you're referring to this tutorial.

    That'd be the wrong one for this case, since your UI is scene-independent. You also want the state of the font to be linked to Options data, meaning it's unaffected by save game values (which is what "Remember" scripts deal with).

    This kind of data is covered in this tutorial. It's more simple than the example there, though, since you need no custom Action to apply the effect - just a script attached to the UI Canvas like you already have.

    Create a Boolean global variable named e.g. "Use larger font", and link it to Options Data. Create a Toggle in your Options menu to allow the user control over it. The tutorial above will show you how, but see also the Manual's "Options data" chapter for more.

    Applying the font is then just a case of attaching the following script:

    using UnityEngine;
    using UnityEngine.UI;
    using AC;
    
    [RequireComponent(typeof(Text))]
    public class ApplyFontSizeOption : MonoBehaviour
    {
    
        public int smallFontSize = 1;
        public int largeFontSize = 2;
        public int optionVariableID;
    
    
        void OnEnable ()
        {
            bool useLargeFont = GlobalVariables.GetBooleanValue (optionVariableID);
            GetComponent <Text>().fontSize = (useLargeFont) ? largeFontSize : smallFontSize;
        }
    
    }
    
  • edited November 2018

    Thanks,

    way simpler solution than i expected :)

    Although it was giving me a warning that the global variable wasn't found. I've put it in a Start() method instead as it needs to be set only once anyway.

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.