void Update() { if (Input.GetMouseButton(1)) { rot = new Vector2( rot.x + Input.GetAxis("Mouse X") * 3, rot.y + Input.GetAxis("Mouse Y") * 3); transform.localRotation = Quaternion.AngleAxis(rot.x, Vector3.up); transform.localRotation *= Quaternion.AngleAxis(rot.y, Vector3.left); } transform.position += transform.forward * 50 * Input.GetAxis("Vertical") * Time.deltaTime; transform.position += transform.right * 50 * Input.GetAxis("Horizontal") * Time.deltaTime; RaycastHit hit; var mousePos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10)); if (Input.GetMouseButtonDown(0)) { bool adjacent = true; if (((Block)blockToPlace).type == Block.Air.type) { adjacent = false; } if (Physics.Raycast(Camera.main.transform.position, mousePos - Camera.main.transform.position, out hit, 100)) { Voxelmetric.SetBlock(hit, blockToPlace, adjacent); } } if (Physics.Raycast(Camera.main.transform.position, mousePos - Camera.main.transform.position, out hit, 100)) { selectedBlockText.text = Voxelmetric.GetBlock(hit).ToString(); } if (saveProgress != null) { saveProgressText.text = SaveStatus(); } else { saveProgressText.text = "Save"; } }
void Update() { if (Input.GetMouseButton(1)) { rot = new Vector2( rot.x + Input.GetAxis("Mouse X") * 3, rot.y + Input.GetAxis("Mouse Y") * 3); transform.localRotation = Quaternion.AngleAxis(rot.x, Vector3.up); transform.localRotation *= Quaternion.AngleAxis(rot.y, Vector3.left); } transform.position += transform.forward * 50 * Input.GetAxis("Vertical") * Time.deltaTime; transform.position += transform.right * 50 * Input.GetAxis("Horizontal") * Time.deltaTime; RaycastHit hit; var mousePos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10)); if (Input.GetMouseButtonDown(0)) { bool adjacent = true; if (((Block)blockToPlace).type == Block.Air.type) { adjacent = false; } if (Physics.Raycast(Camera.main.transform.position, mousePos - Camera.main.transform.position, out hit, 100)) { Voxelmetric.SetBlock(hit, blockToPlace, adjacent); } } if (Physics.Raycast(Camera.main.transform.position, mousePos - Camera.main.transform.position, out hit, 100)) { selectedBlockText.text = Voxelmetric.GetBlock(hit).ToString(); } if (saveProgress != null) { saveProgressText.text = SaveStatus(); } else { saveProgressText.text = "Save"; } if (Input.GetKeyDown(KeyCode.I)) { if (Physics.Raycast(Camera.main.transform.position, mousePos - Camera.main.transform.position, out hit, 100)) { pfStart = Voxelmetric.GetBlockPos(hit); } } if (Input.GetKeyDown(KeyCode.O)) { if (Physics.Raycast(Camera.main.transform.position, mousePos - Camera.main.transform.position, out hit, 100)) { pfStop = Voxelmetric.GetBlockPos(hit); } } if (Input.GetKeyDown(KeyCode.P)) { pf = new PathFinder(pfStart, pfStop, World.instance, 2); Debug.Log(pf.path.Count); } if (pf != null && pf.path.Count != 0) { for (int i = 0; i < pf.path.Count - 1; i++) { Debug.DrawLine(pf.path[i].Add(0, 1, 0), pf.path[i + 1].Add(0, 1, 0)); } } }
void FixedUpdate() { //Scroll to change block if (Input.GetAxis("Mouse ScrollWheel") > 0) { blockToPlaceIndex += 1; } if (Input.GetAxis("Mouse ScrollWheel") < 0) { blockToPlaceIndex -= 1; } //Wrap around if (blockToPlaceIndex < 0) { blockToPlaceIndex = blockToPlace.Length - 1; } if (blockToPlaceIndex > blockToPlace.Length) { blockToPlaceIndex = 0; } //Keypress to change block if (Input.GetKey("1")) { blockToPlaceIndex = 0; } else if (Input.GetKey("2")) { blockToPlaceIndex = 1; } else if (Input.GetKey("3")) { blockToPlaceIndex = 2; } else if (Input.GetKey("4")) { blockToPlaceIndex = 3; } else if (Input.GetKey("5")) { blockToPlaceIndex = 4; } if (Input.GetButtonDown("PrimaryFire")) { RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, range)) { Voxelmetric.SetBlock(hit, "air", false); } } if (Input.GetButtonDown("SecondaryFire")) { RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, range)) { Voxelmetric.SetBlock(hit, blockToPlace[blockToPlaceIndex], true); } } }