private void Update() { m_MouseLook.LookRotation(transform, m_Camera.transform); //착지했을때 if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { m_MoveDir.y = 0f; m_Jumping = false; } //계단을 내려갈 때 if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } //점프키를 누르고 있는데 캐릭터가 땅에 있으면 점프키 입력 판정에 성공하게 한다. if (Input.GetKey(KeyCode.Space) && m_CharacterController.isGrounded) { m_pressedJump = true; } m_PreviouslyGrounded = m_CharacterController.isGrounded; if (Input.GetKeyDown(KeyCode.E)) { uiMgr.panel_Inventory.SetActive(!uiMgr.panel_Inventory.activeSelf); } if (Input.mouseScrollDelta.y > 0) { gameMgr.inventory.ItemBar_SelectSlot(1); } else if (Input.mouseScrollDelta.y < 0) { gameMgr.inventory.ItemBar_SelectSlot(-1); } if (Input.GetKeyDown(KeyCode.Alpha1)) { gameMgr.inventory.ItemBar_SelectSlot(0); } else if (Input.GetKeyDown(KeyCode.Alpha2)) { gameMgr.inventory.ItemBar_SelectSlot(1); } else if (Input.GetKeyDown(KeyCode.Alpha3)) { gameMgr.inventory.ItemBar_SelectSlot(2); } else if (Input.GetKeyDown(KeyCode.Alpha4)) { gameMgr.inventory.ItemBar_SelectSlot(3); } else if (Input.GetKeyDown(KeyCode.Alpha5)) { gameMgr.inventory.ItemBar_SelectSlot(4); } else if (Input.GetKeyDown(KeyCode.Alpha6)) { gameMgr.inventory.ItemBar_SelectSlot(5); } else if (Input.GetKeyDown(KeyCode.Alpha7)) { gameMgr.inventory.ItemBar_SelectSlot(6); } else if (Input.GetKeyDown(KeyCode.Alpha8)) { gameMgr.inventory.ItemBar_SelectSlot(7); } else if (Input.GetKeyDown(KeyCode.Alpha9)) { gameMgr.inventory.ItemBar_SelectSlot(8); } RaycastHit hit; //화면의 정가운데 위치에서 ray변수를 만든다. Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0)); //블록 파괴 if (Input.GetMouseButtonDown(0)) { if (Physics.Raycast(ray, out hit, 6f)) { Vector3 blockPos = hit.transform.position; //맨 아래 블록은 소멸되지 않게 한다. if (blockPos.y <= 0) { return; } gameMgr.mapGenerator.worldBlocks[(int)blockPos.x, (int)blockPos.y, (int)blockPos.z] = null; Particle par = Instantiate(gameMgr.paticles[0], blockPos, Quaternion.LookRotation(Vector3.up)); par.ChangeMaterial(hit.collider.gameObject.GetComponent <MeshRenderer>().material); Destroy(hit.collider.gameObject); //자기 자신을 뺀 이웃들을 인스턴스화한다 for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { for (int z = -1; z <= 1; z++) { //맵 밖 블록에는 접근하지 않도록 한다 if (blockPos.x + x < 0 || blockPos.x + x >= MapGenerator.width_x) { continue; } if (blockPos.y + y < 0 || blockPos.y + y >= MapGenerator.height) { continue; } if (blockPos.z + z < 0 || blockPos.z + z >= MapGenerator.width_z) { continue; } Vector3 neighbour = new Vector3(blockPos.x + x, blockPos.y + y, blockPos.z + z); gameMgr.mapGenerator.RenderBlock(neighbour); } } } } } Debug.DrawRay(Camera.main.transform.position, Camera.main.transform.forward * 100f, Color.red); if (Physics.Raycast(ray, out hit, 6f)) { Debug.DrawRay(Camera.main.transform.position, Camera.main.transform.forward * 100f, Color.red); } //블록 설치 if (Input.GetMouseButtonDown(1)) { if (Physics.Raycast(ray, out hit, 6f)) { Vector3 point = ray.GetPoint(hit.distance); Vector3 axisSide = GetAxisSide(hit.transform.position - ray.GetPoint(hit.distance)); Vector3 blockPos = hit.transform.position - axisSide; gameMgr.mapGenerator.CreateBlock(blockPos, true, Block.Type.Sand); } } }