Search code examples
c#unity-game-engine

Get enum's value as font style


I have created an enum of 3 fonts as shown in script below. I am trying to assign the respective selected font from the inspector window. Unfortunately I do not get the value selected, instead I get an error. What am I doing wrong?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class TextScript : MonoBehaviour {

 public enum fontStyleEnum // your custom enumeration
    {
        Bold, 
        Underline, 
        Italic
    };

    public TMP_Text textMesh; 

    public fontStyleEnum fontStyle;
    
     public void Start(){
        textMesh.fontStyle = FontStyles.fontStyle.value; //I get the error here
    }
}

Solution

  • Variable you are assigning is using enum TMPro.FontStyles and you are trying to assign your fontStyleEnum type.

    Assing it any of TMPro.FontStyles enum and it will work.