這是我的腳本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
Debug.Log("Spase was pressed");
}
}
它非常簡單,我什至嘗試將除錯行更改為跳轉命令,但游戲中仍然沒有回應,為什么我認為它沒有讀取我的輸入,你知道如何修復它嗎?
uj5u.com熱心網友回復:
這肯定會奏效。
如果不能確定:
- 您實際上已將 GameObject 上的腳本作為組件分配
- 當您嘗試按空格時,該游戲物件處于活動狀態
假設您的鍵盤(和空格鍵)正常作業,我能想到的兩件事會使這不起作用。
uj5u.com熱心網友回復:
正如我剛剛被告知大括號不相關,我認為解決您問題的另一種方法可能是替換
KeyCode.Space
和
"space"
否則你可以調查一下。
uj5u.com熱心網友回復:
如果不是放,它可以作業
If (Input.GetKeyDown(KeyCode.Space))
Debug.Log(...)
你輸入
If (Input.GetKeyDown(KeyCode.Space))
{
Debug.Log(...)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/461607.html
下一篇:返回列表