我正在嘗試在我的F#腳本中創建一些UI元素,該腳本連接到Unity 3D中的相機。我知道如何在C#
中執行此操作,但我不確定如何在F#
中執行此操作。如何在F#腳本中創建Unity 3D UI文本元素?
下面是一個簡單C#
例如:
using UnityEngine;
using UnityEngine.UI;
public class CameraController : MonoBehaviour {
public Text uiText;
void Start()
{
uiText.text = "Hello world!";
}
void Update()
{
}
}
現在,這裏是我的F#
代碼。我添加了一些註釋,它們顯示了我在嘗試創建文本元素This type has no accessible constructors
時遇到的編譯器錯誤。
namespace GameLogic
open UnityEngine
open UnityEngine.UI
type CameraController() =
inherit MonoBehaviour()
member this.uiText = Text // Compiler Error: This type has no accessible constructors
member this.Start() =
let uiText = Text // Compiler Error: This Type has no accessible constructors
()
member this.Update() =
()
好像F#
隱式調用Unity的Text
對象的構造方法。
那麼,如何在F#腳本中創建一個ui文本元素?感謝任何和所有的幫助。
庫爾特
謝謝你這個優秀的答案。 –