prototyping
This commit is contained in:
44
Assets/Scripts/ProtoTyping/AlgorithmTest.cs
Normal file
44
Assets/Scripts/ProtoTyping/AlgorithmTest.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AlgorithmTest : MonoBehaviour
|
||||
{
|
||||
public List<float> allHits = new List<float>();
|
||||
public LineRenderer line;
|
||||
public Vector2 offsetMultipliers = Vector2.one;
|
||||
|
||||
void OnDrawGizmos(){
|
||||
RegenerateLines();
|
||||
}
|
||||
|
||||
void RegenerateLines(){
|
||||
Vector3[] points = new Vector3[allHits.Count];
|
||||
|
||||
for(int i=0; i < points.Length; i++){
|
||||
points[i] = GetPosition(i);
|
||||
}
|
||||
|
||||
line.positionCount = points.Length;
|
||||
line.SetPositions(points);
|
||||
}
|
||||
|
||||
Vector3 GetPosition(int index) {
|
||||
float hitX = allHits[index];
|
||||
|
||||
float diff = 0;
|
||||
float prevY = 0;
|
||||
|
||||
// Calculate diff and prevY if the index is greater than 0
|
||||
if (index > 0) {
|
||||
diff = allHits[index] - allHits[index - 1];
|
||||
prevY = GetPosition(index - 1).y; // Recursively get the previous Y value
|
||||
}
|
||||
|
||||
float flipSide = index % 2 == 0 ? 1 : -1;
|
||||
float y = prevY + (flipSide * diff);
|
||||
|
||||
return new Vector3(hitX * offsetMultipliers.x, y, 0);
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/ProtoTyping/AlgorithmTest.cs.meta
Normal file
11
Assets/Scripts/ProtoTyping/AlgorithmTest.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4211f2cde196b14cb9d69a4879ae7cc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user