private void Move() { // if (Input.GetKey(KeyCode.Space)) // { // if (Input.GetKeyDown(KeyCode.UpArrow) && m_PresentLength < m_MaxLength && m_Map.EasyMap[PresentX, PresentY + 1] == 0) // { // PresentY++; // m_PresentLength++; // transform.position += UpMove; // Instantiate(m_Body, m_HeadPosition, ZeroQuaternion); // m_HeadPosition = transform.position; // m_Map.EasyMap[PresentX, PresentY] = 1; // } // if (Input.GetKeyDown(KeyCode.DownArrow) && m_PresentLength < m_MaxLength && m_Map.EasyMap[PresentX, PresentY - 1] == 0) // { // PresentY--; // m_PresentLength++; // transform.position -= UpMove; // Instantiate(m_Body, m_HeadPosition, ZeroQuaternion); // m_HeadPosition = transform.position; // m_Map.EasyMap[PresentX, PresentY] = 1; // } // if (Input.GetKeyDown(KeyCode.RightArrow) && m_PresentLength < m_MaxLength && m_Map.EasyMap[PresentX + 1, PresentY] == 0) // { // PresentX++; // m_PresentLength++; // transform.position += RightMove; // Instantiate(m_Body, m_HeadPosition, ZeroQuaternion); // m_HeadPosition = transform.position; // m_Map.EasyMap[PresentX, PresentY] = 1; // } // if (Input.GetKeyDown(KeyCode.LeftArrow) && m_PresentLength < m_MaxLength && m_Map.EasyMap[PresentX - 1, PresentY] == 0) // { // PresentX--; // m_PresentLength++; // transform.position -= RightMove; // Instantiate(m_Body, m_HeadPosition, ZeroQuaternion); // m_HeadPosition = transform.position; // m_Map.EasyMap[PresentX, PresentY] = 1; // } // } if (Input.GetKey(KeyCode.Space) && m_PresentLength < m_MaxLength) { Vector3Int moveDir = Vector3Int.zero; if (Input.GetKeyDown(KeyCode.UpArrow)) { moveDir = new Vector3Int(0, 1, 0); } if (Input.GetKeyDown(KeyCode.DownArrow)) { moveDir = new Vector3Int(0, -1, 0); } if (Input.GetKeyDown(KeyCode.RightArrow)) { moveDir = new Vector3Int(1, 0, 0); } if (Input.GetKeyDown(KeyCode.LeftArrow)) { moveDir = new Vector3Int(-1, 0, 0); } if (moveDir.magnitude == 0) { return; } if (MapManager.CanMoveOn(PresentX + moveDir.x, PresentY + moveDir.y)) { PresentX += moveDir.x; PresentY += moveDir.y; m_PresentLength++; transform.position += moveDir; Instantiate(m_Body, m_HeadPosition, ZeroQuaternion); m_HeadPosition = transform.position; MapManager.AddObject(PresentX, PresentY, Cell.CellObjectType.SnakeBody); } } if (Input.GetKeyUp(KeyCode.Space)) { m_PresentLength = 1; } }