public void AddSegment(HullPoint a_point1, HullPoint a_point2) { var segment = new LineSegment(a_point1.Pos, a_point2.Pos); // dont add double segments if (m_segments.Contains(segment) || m_segments.Contains(new LineSegment(a_point2.Pos, a_point1.Pos))) { // also check reverse return; } m_segments.Add(segment); // instantiate new road mesh var roadmesh = Instantiate(m_roadMeshPrefab, Vector3.forward, Quaternion.identity) as GameObject; roadmesh.transform.parent = this.transform; instantObjects.Add(roadmesh); roadmesh.GetComponent <HullSegment>().Segment = segment; var roadmeshScript = roadmesh.GetComponent <ReshapingMesh>(); roadmeshScript.CreateNewMesh(a_point1.transform.position, a_point2.transform.position); CheckSolution(); }
void Update() { if (m_locked && !Input.GetMouseButton(0)) { // create road AddSegment(m_firstPoint, m_secondPoint); } else if (Input.GetMouseButton(0)) { // update road endpoint var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition + 10 * Vector3.forward); m_line.SetPosition(1, pos); } // clear road creation variables if ((m_locked && !Input.GetMouseButton(0)) || Input.GetMouseButtonUp(0)) { m_locked = false; m_firstPoint = null; m_secondPoint = null; m_line.enabled = false; } }