Здесь я генерирую средство визуализации линий с несколькими точками, чтобы создать волну из точек, и теперь мне нужно получить доступ к некоторым точкам в этом списке, чтобы выполнить дальнейшие вычисления над ним.
![enter image description here](https://i.stack.imgur.com/FQ9Z3.png)
Проблема в том, что список Vector 2, который я использую для добавления точек, не показывает те же точки, что и параметр Positions в компоненте средства визуализации строк, так как я также перемещаю родительский компонент, в котором используется этот инструмент визуализации линий компонент присоединен, и положение в компоненте рендерера линий по умолчанию показывает позиционные значения в World Space, к которым я должен получить доступ, тогда как сгенерированный мной список Vector 2 показывает точки в Local Space, где только одно значение выглядит как меняется.
![enter image description here](https://i.stack.imgur.com/0gKtC.png)
Как я могу получить доступ к мировым космическим значениям, не изменяя слишком много моей текущей архитектуры?
Мне нужно получить доступ к точкам оси Z в элементах Positions компонента Line Renderer для сравнения позиционных значений, а также для получения индекса тех же точек.
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(LineRenderer))]
public class tail : MonoBehaviour {
public GameObject tailComponent, diameterBall, playButton, statisticalToolSubLevel;
public float speed;
public float pointSpacing = .01f;
public List<Vector2> points;
LineRenderer line;
public Text maxima, minima, mean, median;
public TapToMeasure otherScript;
// Use this for initialization
void Start () {
line = GetComponent<LineRenderer>();
points = new List<Vector2>();
SetPoint();
}
// Update is called once per frame
void Update () {
if (!playButton.activeSelf)
{
if (Vector3.Distance(points.Last(), diameterBall.transform.position) > pointSpacing)
{
SetPoint();
}
}
/*
int result1 = 0;
result1 = BinarySearchRecursive(points.position.x, otherScript.statisticalMarkerList[0].transform.position.x, 0, points.Count);
*/
if (statisticalToolSubLevel.activeSelf)
{
for(int i=0; i<points.Count; i++)
{
if(Mathf.Approximately(points[i].x, otherScript.statisticalMarkerList[0].transform.position.x))
{
Debug.Log("Task acheieved");
//return i;
}
if (points[i].x < otherScript.statisticalMarkerList[0].transform.position.x)
{
i += 1;
//Debug.Log(i);
}
}
}
}
void SetPoint()
{
points.Add(diameterBall.transform.position);
line.positionCount = points.Count; //count<=100 or whatever number or edge of the room
//line.SetPosition(points.Count - 1, diameterBall.transform.position);
line.SetPosition(points.Count - 1, tailComponent.transform.InverseTransformPoint(diameterBall.transform.position));
}
public static int BinarySearchRecursive(float[] inputArray, float query, int min_idx, int max_idx)
{
if (min_idx > max_idx)
{
return -1;
}
else
{
int mid = (min_idx + max_idx) / 2;
if (query == inputArray[mid])
{
return mid;
}
else if (query < inputArray[mid])
{
return BinarySearchRecursive(inputArray, query, min_idx, mid);
}
else if (min_idx + 1 == max_idx)
{
return mid;
}
else
{
return BinarySearchRecursive(inputArray, query, mid, max_idx);
}
}
}
}