Scriptum/Assets/HardLight2D/Demo/DemoScripts/PolyWobbler.cs

30 lines
808 B
C#
Raw Normal View History

2022-12-29 03:22:45 +01:00
using UnityEngine;
[RequireComponent (typeof (LineRenderer))]
[RequireComponent (typeof (PolygonCollider2D))]
public class PolyWobbler : MonoBehaviour
{
PolygonCollider2D Poly;
LineRenderer LineRend;
public float Wobbles = 1;
Vector2[] points;
private void Start ()
{
Poly = GetComponent<PolygonCollider2D> ();
LineRend = GetComponent<LineRenderer> ();
}
void Update ()
{
points = Poly.GetPath (0);
LineRend.positionCount = points.Length;
for (int i = 0; i < points.Length; i++)
{
points[i] += Random.insideUnitCircle * Time.deltaTime * Wobbles;
LineRend.SetPosition (i, points[i]);
}
Poly.SetPath (0, points);
HardLight2DManager.RefreshColliderReference (Poly);
}
}