iLMS知識社群歷程檔登入
位置: 黃國哲 > Unity
1110319 鍵盤代碼 KeyCode 用法
by 黃國哲 2022-03-19 15:46:37, 回應(0), 人氣(399)

https://docs.unity3d.com/ScriptReference/KeyCode.html

宣告這個變數
public KeyCode keycode;

可以讓按鈕物件和鍵盤的實體按鈕直接做連結

void Update () {
//Keypresses. The keycode is stores in the ButtonSetup class
if(Input.anyKeyDown){
foreach(Transform t in buttonHolder.transform){
if(Input.GetKeyDown (t.gameObject.GetComponent.keycode) ){
t.gameObject.GetComponent < Butto >().OnPointerClick (


new UnityEngine.EventSystems.PointerEventData(UnityEngine.EventSystems.EventSystem.current));

回應