Unity-输入系统
前言
游戏开发中,不论是动作游戏,还是RPG,甚至于放置类,都会使用到输入系统,以下是Unity中实现输入的一些使用经验,以及代码用例
输入系统
Unity目前的输入系统有Input,Input System两种, 以下是相关代码示例
Input
旧版本的输入控制系统
键盘按键输入
if (Input.GetKeyDown(KeyCode.Q))
{
Debug.Log("按下Q");
}
if (Input.GetKeyDown(KeyCode.R))
{
Debug.Log("按下R");
}
移动输入
//左右
float horizontal= Input.GetAxisRaw("Horizontal");
//上下
float vertical= Input.GetAxisRaw("Vertical");
if (horizontal==1)
{
Debug.Log("右");
}
if (horizontal==-1)
{
Debug.Log("左");
}
if (vertical==1)
{
Debug.Log("上");
}
if (vertical==-1)
{
Debug.Log("下");
}
Input System
新版的输入控制系统
----待补充