获取枚举值作为字体样式

问题描述 投票:0回答:3

我创建了 3 种字体的枚举,如下面的脚本所示。我正在尝试从检查器窗口中分配相应的选定字体。不幸的是,我没有得到所选的值,而是收到错误。我做错了什么?

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
    }
}
c# unity-game-engine
3个回答
0
投票

您正在分配的变量正在使用枚举

TMPro.FontStyles
并且您正在尝试分配您的
fontStyleEnum
类型。

对任何

TMPro.FontStyles
枚举进行评估,它将起作用。


0
投票

公共枚举产品功能 { Talkdesk, [Description("捆绑购买")] 捆绑购买, [Description("AI Chat")] AIChat } 我想要这个 Talkdesk,捆绑购买,AI 聊天为粗体


-1
投票

FontStyles 没有名为

fontStyle
的字段。

您必须获取枚举并将其转换为FontStyles

参见:

public void Start()
{
    textMesh.fontStyle = (FontStyles)fontStyle;
}
© www.soinside.com 2019 - 2024. All rights reserved.