private void CreatePart(ScrollablePart part) { GameObject partGO = GameObject.Instantiate(part.gameObject); PartController newPart = partGO.GetComponent <PartController>(); newPart.Init(); float nextPartPos; if (currentParts.Count > 0) { var lastPart = currentParts[currentParts.Count - 1]; nextPartPos = direction.Equals(DIRECTION.HORIZONTAL) ? lastPart.transform.position.x + newPart.bounds.x : lastPart.transform.position.y + newPart.bounds.y; } else { nextPartPos = direction.Equals(DIRECTION.HORIZONTAL) ? transform.position.x : transform.position.y; } partGO.transform.position = direction.Equals(DIRECTION.HORIZONTAL) ? new Vector3(nextPartPos, transform.position.y, transform.position.z): new Vector3(transform.position.x, nextPartPos, transform.position.z); partGO.transform.rotation = Quaternion.identity; currentParts.Add(newPart); }
private void CheckRemovePart(ScrollablePart part) { pos = direction.Equals(DIRECTION.HORIZONTAL) ? part.transform.position.x : part.transform.position.y; boundPos = direction.Equals(DIRECTION.VERTICAL) ? removeBound.x : removeBound.y; if (pos < boundPos) { currentParts.Remove(part); Destroy(part.gameObject); } }