我創建了一個包含 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
}
}
uj5u.com熱心網友回復:
您正在分配的變數正在使用列舉,TMPro.FontStyles并且您正在嘗試分配您的fontStyleEnum型別。
對它進行任何TMPro.FontStyles列舉,它都會起作用。
uj5u.com熱心網友回復:
FontStyles沒有名為 的欄位fontStyle。
你必須把你的 enum 轉換為FontStyles。
看:
public void Start()
{
textMesh.fontStyle = (FontStyles)fontStyle;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/329222.html
