How to instantiate spheres and delete old ones based on coordinates I get
Hello everyone, Iam new to Unity scripting and c# and would like to do the following:
I constantly get x y coordinates which represent laser scan data. I would like to draw spheres on each of the x y points.
Basically the laserscan data consist of up to 100 points which will repeat themselves if the laserscanner is not moved. So i will constantly get a x y data stream (if laser is not movied, then always the same points). If I move the scanner, I will get new points and some old points will not be sent because they are not visible for the laser scanner anymore.
Now for each x y point i would like to draw a sphere and at the same time, if the laser scanner moves and gives new points i want to display the new points and delete old ones which are not visible.
For now I have implemented that for every xy point to draw the spheres but struggled with the deletion algorithm. So now it draws spheres at new points but also keep the old ones on the scene I want to delete the ones which coordinates are not being sent anymore.
my script is as following:
...... public class SpawnPoints : MonoBehaviour {
public GameObject point;
public Vector3 spawnValues;
public float spawnWait;
public float spawnMostWait;
public float spawnLeastWait;
public int startWait;
public bool stop;
public GameObject sensorf;
public SensorReceive sensorscript;
public GeometryPoint pt
private void Start()
{
// get x and y from sensorReceive script
sensorf = GameObject.Find("SensorReceiver");
sensorscript = sensorf.GetComponent<SensorReceive>();
StartCoroutine(waitSpawner());
}
private void Update()
{
spawnWait = 0.00f;
}
IEnumerator waitSpawner()
{
while (!stop)
{
// spawn spheres at x and y position from sensorscript
Vector3 spawnPosition = new Vector3(sensorscript.x, 1, sensorscript.y);
Instantiate(point, spawnPosition + transform.TransformPoint(0, 0, 0), gameObject.transform.rotation);
yield return new WaitForSeconds(spawnWait);
}
}
Please help me because I struggled for 2 days and also searched for examples. Big thanks in advance! Best regards