// Check point exactly public Vector3 PointInLine(BaseSlicerLine slicerLine, Line normalLine) { Vector3 result = Vector3.zero; if (slicerLine.direction == LineDirection.UP || slicerLine.direction == LineDirection.DOWN) { if (normalLine.direction == LineDirection.UP || normalLine.direction == LineDirection.DOWN) { // If closer to start if (Vector3.Distance(slicerLine.end, normalLine.end) >= Vector3.Distance(slicerLine.end, normalLine.start)) { normalLine = normalLine.GetShape().FindLineByEnd(normalLine.start); } // If closer to end else { normalLine = normalLine.GetShape().FindLineByStart(normalLine.end); //GameObject dup = Instantiate(normalLine.gameObject); } } result.x = slicerLine.start.x; result.y = normalLine.start.y; info.line = normalLine; line = normalLine; } else { if (normalLine.direction == LineDirection.LEFT || normalLine.direction == LineDirection.RIGHT) { // If closer to start if (Vector3.Distance(slicerLine.end, normalLine.end) >= Vector3.Distance(slicerLine.end, normalLine.start)) { normalLine = normalLine.GetShape().FindLineByEnd(normalLine.start); } // If closer to end else { normalLine = normalLine.GetShape().FindLineByStart(normalLine.end); } } result.x = normalLine.start.x; result.y = slicerLine.start.y; info.line = normalLine; line = normalLine; } return(result); }
public void Create() { rotate = true; hit = false; available = false; this.type = (SliceType)Random.Range(0, 2); this.sprite.transform.rotation = Quaternion.identity; this.sprite.transform.DOKill(); this.sprite.transform.localScale = Vector3.one * 0.75f; GameObject firstLine = Instantiate(linePrefab, transform.position, Quaternion.identity, transform); GameObject secondLine = Instantiate(linePrefab, transform.position, Quaternion.identity, transform); first = firstLine.GetComponent <BaseSlicerLine>(); second = secondLine.GetComponent <BaseSlicerLine>(); if (this.type == SliceType.CORNER) { this.sprite.sprite = corner; first.Create(LineDirection.UP, this); second.Create(LineDirection.RIGHT, this); } else { this.sprite.sprite = straight; first.Create(LineDirection.LEFT, this); second.Create(LineDirection.RIGHT, this); } int rotateTime = Random.Range(0, 4); for (int i = 0; i < rotateTime; i++) { Rotate(); } }