【发布时间】:2019-10-19 23:32:07
【问题描述】:
我正在开发一个 4 方向(上、下、左、右)的 2D 游戏,它会使用基于网格的运动,但我无法弄清楚如何解决。
公共类播放器:角色 {
/// <summary>
/// Overridin the characters update function, so that we can execute our own functions
/// </summary>
protected override void Update()
{
//Executes the GetInput function
GetInput();
base.Update();
}
/// <summary>
/// Listen's to the players input
/// </summary>
private void GetInput()
{
direction = Vector2.zero;
//Movement
if (Input.GetKey(KeyCode.UpArrow))
{
direction += Vector2.up;
}
else if (Input.GetKey(KeyCode.LeftArrow))
{
direction += Vector2.left;
}
else if (Input.GetKey(KeyCode.DownArrow))
{
direction += Vector2.down;
}
else if (Input.GetKey(KeyCode.RightArrow))
{
direction += Vector2.right;
}
}
【问题讨论】: