remaining cleanup

This commit is contained in:
2024-09-28 12:20:44 -05:00
parent 07550888a8
commit 1e7048f4dd
3 changed files with 8 additions and 14 deletions

View File

@@ -1,6 +1,4 @@
using System;
using UnityEngine; using UnityEngine;
using Random = UnityEngine.Random;
public class Asteroid : MonoBehaviour public class Asteroid : MonoBehaviour
{ {

View File

@@ -1,6 +1,3 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class Point : MonoBehaviour public class Point : MonoBehaviour

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Serialization;
using Random = UnityEngine.Random; using Random = UnityEngine.Random;
[RequireComponent(typeof(LineRenderer), typeof(Collider2D))] [RequireComponent(typeof(LineRenderer), typeof(Collider2D))]
@@ -55,9 +51,11 @@ public class Shaper : MonoBehaviour
var previousRadius = radius; var previousRadius = radius;
// Generate points // Generate points
for (var i = 0; i < pointCount; i++) { for (var i = 0; i < pointCount; i++)
{
var rad = Mathf.Deg2Rad * (i * 360f / pointCount); var rad = Mathf.Deg2Rad * (i * 360f / pointCount);
var pointRadius = previousRadius * maxChange + (radius + Random.Range(jaggedLow, jaggedHigh)) * (1f - maxChange); var pointRadius = previousRadius * maxChange +
(radius + Random.Range(jaggedLow, jaggedHigh)) * (1f - maxChange);
points[i] = new Vector3(Mathf.Sin(rad) * pointRadius, Mathf.Cos(rad) * pointRadius, 0); points[i] = new Vector3(Mathf.Sin(rad) * pointRadius, Mathf.Cos(rad) * pointRadius, 0);
previousRadius = pointRadius; previousRadius = pointRadius;
} }
@@ -65,13 +63,14 @@ public class Shaper : MonoBehaviour
// Add points to LineRenderer // Add points to LineRenderer
_lineRenderer.SetPositions(points); _lineRenderer.SetPositions(points);
// Use the linerenderer's Vector3's to create vector2 collider path // Use the line-renderer's Vector3's to create vector2 collider path
var path = new Vector2[_lineRenderer.positionCount + 1]; var path = new Vector2[_lineRenderer.positionCount + 1];
for (var i = 0; i < pointCount; i++) for (var i = 0; i < pointCount; i++)
{ {
// Convert Vector3 to Vector2 // Convert Vector3 to Vector2
path[i] = points[i]; path[i] = points[i];
} }
path[_lineRenderer.positionCount] = path[0]; path[_lineRenderer.positionCount] = path[0];
_polygonCollider.SetPath(0, path); _polygonCollider.SetPath(0, path);
} }