// Update is called once per frame void Update() { // Preview line stuff if (IsDraggingWire) { // Set active PreviewLine.gameObject.SetActive(true); // Get some shorter-named variables float MouseX = Input.mousePosition.x; float MouseY = Screen.height - Input.mousePosition.y; float ImageWidth = 14 * (Screen.width / 2560f); // Set the points on the line renderer Vector2 LRPoint1 = Camera.main.ScreenToWorldPoint(new Vector2(DraggingOrigin.x + ImageWidth / 2f, DraggingOrigin.y - ImageWidth / 2f)); Vector2 LRPoint2 = Camera.main.ScreenToWorldPoint(new Vector2(MouseX + ImageWidth / 2f, Screen.height - MouseY - ImageWidth / 2f)); PreviewLine.SetPositions(new Vector3[] { new Vector3(LRPoint1.x, LRPoint1.y, -7), new Vector3(LRPoint2.x, LRPoint2.y, -7) }); PreviewLine.sortingOrder = 4; } else { PreviewLine.gameObject.SetActive(false); } // Handle viewing panel stuff if (_LevelManager.ViewingPanel) { // Check for player clicks. Record the position if so. if (Input.GetMouseButtonUp(0)) { // First we need to know if we hit the switch, if we're clicking to place // a logic gate or if we're dragging the view around (maybe not the last one?) if (MouseInBounds) { // Get the player's mouse position in world co-ordinates Vector2 MouseWorldCoords = Camera.main.ScreenToWorldPoint(Input.mousePosition); // Spawn a logic gate or create wiring depending on the tool if (CurrentTool == PlayerTool.PlaceGate) { // Play a sound DropSound.Play(); // Spawn the selected logic gate at mouse position switch (SelectedGate) { case GateSelection.AND: Gates.SpawnGate(Gates.Gate_AND, MouseWorldCoords); break; case GateSelection.NAND: Gates.SpawnGate(Gates.Gate_NAND, MouseWorldCoords); break; case GateSelection.OR: Gates.SpawnGate(Gates.Gate_OR, MouseWorldCoords); break; case GateSelection.NOR: Gates.SpawnGate(Gates.Gate_NOR, MouseWorldCoords); break; case GateSelection.XOR: Gates.SpawnGate(Gates.Gate_XOR, MouseWorldCoords); break; case GateSelection.XNOR: Gates.SpawnGate(Gates.Gate_XNOR, MouseWorldCoords); break; case GateSelection.NOT: Gates.SpawnGate(Gates.Gate_NOT, MouseWorldCoords); break; } } } } // Right-clicking stops dragging a wire if (Input.GetMouseButtonUp(1)) { IsDraggingWire = false; GateDraggingFrom = null; DropSound.Play(); } } }