//Method used to add a new line renderer vertex and a new vertex sphere. public GameObject addVertex(Vector3 pos, int vertexID, GameObject selectedVertex) { pos = rotateVertex(pos, -getLocalRotation()); //Get the vertex spheres that are children of this object List <GameObject> children = getChildrenVertices(); //Add the selected vertex to that list (as it won't be a child of the object if it's selected), and sort the list. if (selectedVertex) { children.Add(selectedVertex); } children.Sort(sortByVertexID); //for loop to go through each vertex and update it's vertexID if it's PAST the selected vertex foreach (GameObject child in children) { VertexManager childsVM = child.GetComponent <VertexManager>(); if (childsVM.getVertexID() >= vertexID) { childsVM.setVertexID(childsVM.getVertexID() + 1); } } //create a new vertex sphere GameObject newVert = drawVert(pos, vertexID, false); VertexManager newVertsVM = newVert.GetComponent <VertexManager>(); //make the new vertex's size and "length" field equal to the one currently selected if (selectedVertex) { newVert.transform.localScale = selectedVertex.transform.lossyScale; newVertsVM.setVertexLength(selectedVertex.GetComponent <VertexManager>().getVertexLength()); } //add this new vertex to the dictionary of vertexmanagers with its current timing timingDict[newVertsVM.getVertexTiming()].Add(newVertsVM); //add this new vertex to the list of children, and sort the list again. children.Add(newVert); children.Sort(sortByVertexID); //create a Vector3[] to hold the positions that the line renderer will be set to. Vector3[] finalPositions = new Vector3[children.Count]; //translate the position of every child and add it to finalPositions. for (int i = 0; i < children.Count; i++) { Vector3 tempPos = children[i].transform.position; tempPos = rotateVertex(tempPos, -getLocalRotation()); //tempPos = vertexRotationTwo(tempPos, localRotation+270, i); finalPositions[i] = tempPos; } //create a new vertex on the line renderer and set it's positions to finalPositions. attachedLR.positionCount += 1; attachedLR.SetPositions(finalPositions); boxColliderManager.addBoxCollider(vertexID); return(newVert); }