我创建了 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
}
}
您正在分配的变量正在使用枚举
TMPro.FontStyles
并且您正在尝试分配您的 fontStyleEnum
类型。
对任何
TMPro.FontStyles
枚举进行评估,它将起作用。
公共枚举产品功能 { Talkdesk, [Description("捆绑购买")] 捆绑购买, [Description("AI Chat")] AIChat } 我想要这个 Talkdesk,捆绑购买,AI 聊天为粗体
FontStyles 没有名为
fontStyle
的字段。
您必须获取枚举并将其转换为FontStyles。
参见:
public void Start()
{
textMesh.fontStyle = (FontStyles)fontStyle;
}