| 1 | using System.Collections; |
| 2 | using System.Collections.Generic; |
| 3 | using UnityEngine; |
| 4 | |
| 5 | public class WireThread : MonoBehaviour |
| 6 | { |
| 7 | [SerializeField] private Transform wireThreadStartA, wireThreadStartB; |
| 8 | private LineRenderer lineRenderer; |
| 9 | |
| 10 | private float lineBendSize = 0.3f; |
| 11 | private int lineSections = 50; |
| 12 | |
| 13 | private Color[] colors = |
| 14 | { |
| 15 | Color.green, |
| 16 | Color.blue, |
| 17 | Color.red, |
| 18 | Color.yellow, |
| 19 | Color.black, |
| 20 | Color.white, |
| 21 | Color.cyan, |
| 22 | Color.gray |
| 23 | }; |
| 24 | |
| 25 | void Start() |
| 26 | { |
| 27 | lineRenderer = GetComponent<LineRenderer>(); |
| 28 | Color color = colors[Random.Range(0, colors.Length)]; |
| 29 | lineRenderer.SetColors(color, color); |
| 30 | |
| 31 | lineRenderer.positionCount = lineSections; |
| 32 | } |
| 33 | |
| 34 | void FixedUpdate() |
| 35 | { |
| 36 | Vector3[] points = new Vector3[] |
| 37 | { |
| 38 | wireThreadStartA.transform.position, |
| 39 | wireThreadStartA.transform.position + (wireThreadStartA.transform.forward * lineBendSize), |
| 40 | wireThreadStartB.transform.position + (wireThreadStartB.transform.forward * lineBendSize), |
| 41 | wireThreadStartB.transform.position |
| 42 | }; |
| 43 | |
| 44 | for(int i = 0; i < lineSections; i++) |
| 45 | { |
| 46 | lineRenderer.SetPosition(i, Curving.Lerp(points, (float)i / (float)(lineSections - 1))); |
| 47 | } |
| 48 | } |
| 49 | } |