Unity - 获取玩家输入
Unity - Getting Player Input
我正在 Unity 中制作一个基本游戏,需要知道如何获得玩家的输入。当我搜索这个时,我在每个网站上都得到了相同的结果,让我输入一行代码。
我试着输入这行代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScrScrScrScrScr : MonoBehaviour
{
public GameObject Square;
private MeshRenderer myRenderer;
// 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("Space key was pressed.");
}
}
}
这没有任何作用,每次我按下 space 都没有任何反应。
该代码没有问题。您是否将此脚本放在场景中的游戏对象上?你在看控制台看它是否吐出调试?最后...class 名字怎么了?
我正在 Unity 中制作一个基本游戏,需要知道如何获得玩家的输入。当我搜索这个时,我在每个网站上都得到了相同的结果,让我输入一行代码。
我试着输入这行代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScrScrScrScrScr : MonoBehaviour
{
public GameObject Square;
private MeshRenderer myRenderer;
// 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("Space key was pressed.");
}
}
}
这没有任何作用,每次我按下 space 都没有任何反应。
该代码没有问题。您是否将此脚本放在场景中的游戏对象上?你在看控制台看它是否吐出调试?最后...class 名字怎么了?