void Update() { //Chech that a step is done only every deltaTimeStep and press space in the keyboard to pause/start timePassed += Time.deltaTime; if (timePassed >= deltaTimeStep) { timePassed = 0.0f; } if (!isPaused && timePassed == 0.0f) { int gridSize = gridSizeNew + gridSizeNew * (gridSizeNew - 1); //int gridSize = gridSizeNew + (gridSizeNew - 1); simulator.Update(deltaTimeStep, _triangles, _edges); UpdateMesh(); UpdateEdges(); } if (Input.GetKeyDown(KeyCode.Space)) { isPaused = !isPaused; } // Sets an anchor with right mouse click if (Input.GetMouseButtonDown(1)) { this.ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(this.ray, out this.hit)) { this.hit.collider.GetComponent <ParticlesBehaviour>().particles.isActive = false; } this.screenPoint = Camera.main.WorldToScreenPoint(this.transform.position); } if (Input.GetKey("left")) { this.hit.collider.GetComponent <ParticlesBehaviour>().particles.AddPosition(new Vector3(0.01f, 0f, 0f)); } if (Input.GetKey("right")) { this.hit.collider.GetComponent <ParticlesBehaviour>().particles.AddPosition(new Vector3(-0.01f, 0f, 0f)); } if (Input.GetKey("up")) { this.hit.collider.GetComponent <ParticlesBehaviour>().particles.AddPosition(new Vector3(0f, 0f, 0.01f)); } if (Input.GetKey("down")) { this.hit.collider.GetComponent <ParticlesBehaviour>().particles.AddPosition(new Vector3(0f, 0f, -0.01f)); } if (Input.GetKey("w")) { this.hit.collider.GetComponent <ParticlesBehaviour>().particles.AddPosition(new Vector3(0f, 0.01f, 0f)); } if (Input.GetKey("s")) { this.hit.collider.GetComponent <ParticlesBehaviour>().particles.AddPosition(new Vector3(0f, -0.01f, 0f)); } // While left mouse click is held down you can drag particles around if (Input.GetMouseButtonDown(0)) { this.ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(this.ray, out this.hit)) { this.hit.collider.GetComponent <ParticlesBehaviour>().particles.isActive = false; } this.screenPoint = Camera.main.WorldToScreenPoint(this.transform.position); offsett = this.hit.collider.GetComponent <ParticlesBehaviour>().particles.Position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z)); } if (Input.GetMouseButton(0)) { var currentScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z); var currentPosition = Camera.main.ScreenToWorldPoint(currentScreenPoint) + offsett; this.hit.collider.GetComponent <ParticlesBehaviour>().particles.Position = currentPosition; this.transform.position = currentPosition; //UpdateMesh(); } // Unsets an anchor with middle mouse click if (Input.GetMouseButtonDown(2)) { this.ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(this.ray, out this.hit)) { this.hit.collider.GetComponent <ParticlesBehaviour>().particles.isActive = true; } } }