public void RemoveLastAddedSegment() { if (activeSegment != null) { Destroy(activeSegment.gameObject); } activeSegment = oldSegments.Pop <StretchyThing>(); }
public void AddSegment(Vector3 from, Vector3 to, Vector3 scale) { // lastAddedSegment is now old and will be replaced with new segment if (activeSegment != null) { oldSegments.Add(activeSegment); } activeSegment = createNewLineSegement(scale); activeSegment.Stretch(from, to); activeSegment.transform.parent = transform; }
//--------------------------------------------------------------------------HELPERS: private StretchyThing createNewLineSegement(Vector3 scale) { GameObject newLine = Instantiate(LinePrefab); newLine.transform.localScale = scale; StretchyThing newLineStretchyThing = newLine.GetComponent <StretchyThing>(); if (newLineStretchyThing != null) { return(newLineStretchyThing); } return(newLine.AddComponent <StretchyThing>()); }
public void Clear() { if (oldSegments != null) { foreach (StretchyThing segment in oldSegments) { GameObject.Destroy(segment.gameObject); } } if (activeSegment != null) { GameObject.Destroy(activeSegment.gameObject); } oldSegments = new List <StretchyThing>(); activeSegment = null; }