private void Update() { if (world == null) { return; } if (selectionBox.transform.parent == null) { selectionBox.transform.SetParent(world.transform); selectionBox.transform.localRotation = Quaternion.identity; selectionBox.transform.localScale = Vector3.one; } if (Time.time - lastPlace < editCooldown) { return; } SelectedBlock sel = GetSelectedBlock(); if (!sel.hasSelectedBlock) { selectionBox.SetActive(false); return; } selectionBox.SetActive(true); if (selectionInside) { selectionBox.transform.localPosition = new Vector3(sel.xOn, sel.yOn, sel.zOn) + Vector3.one * 0.5f; } else { selectionBox.transform.localPosition = new Vector3(sel.xInside, sel.yInside, sel.zInside) + Vector3.one * 0.5f; } if (HasRequestedPlace() && block != null) { if (CanPlaceBlockAt(sel.xInside, sel.yInside, sel.zInside)) { lastPlace = Time.time; world.SetBlock(sel.xInside, sel.yInside, sel.zInside, block); } } else if (HasRequestedBreak()) { lastPlace = Time.time; world.SetBlock(sel.xOn, sel.yOn, sel.zOn, null); } }
protected void Update() { if (Input.GetMouseButtonDown(0)) { var target = RaycastWorld; if (target.HasBlock) { m_BlockWorld.SetBlock(target.Over, 1); } } if (Input.GetMouseButtonDown(1)) { var target = RaycastWorld; if (target.HasBlock) { m_BlockWorld.SetBlock(target.Inside, 2); } } }
protected override void OnMouseDown(MouseButtonEventArgs e) { base.OnMouseDown(e); if (e.Button == MouseButton.Left && !CursorVisible) { Vector3?intersection = FindIntersection(false); if (intersection.HasValue && world.SetBlock(intersection.Value, Blocks.Air)) { } } if (e.Button == MouseButton.Right && !CursorVisible) { Vector3?intersection = FindIntersection(true); if (intersection.HasValue && world.SetBlock(intersection.Value, inventory[slot]) && !CanMoveTo(camera.Position)) { world.SetBlock(intersection.Value, Blocks.Air); } } if (e.Button == MouseButton.Left && CursorVisible) { CursorVisible = false; } }