BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / GAME / Scripts / Components / WireThread.cs

WireThread.cs

Project Import
timfa Tim Falken · pushed by timfa · 6 years ago
b77834a1 History
WireThread.cs 1.3 KiB Download Raw
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4
5public 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}