Skip to content

Instantly share code, notes, and snippets.

@tarukosu
Created July 30, 2017 12:12
Show Gist options
  • Select an option

  • Save tarukosu/fd17f182796aa137805d3e8e8dba6f9b to your computer and use it in GitHub Desktop.

Select an option

Save tarukosu/fd17f182796aa137805d3e8e8dba6f9b to your computer and use it in GitHub Desktop.
SweepVisualizer.cs
using System.Collections.Generic;
using UnityEngine;
namespace UnitySweep {
public class SweepVisualizer : MonoBehaviour {
public GameObject PointPrefab;
Sweep Sweep;
List<GameObject> pointList;
void Start() {
pointList = new List<GameObject>();
Sweep = GetComponent<Sweep>();
Sweep.ScanUpdated += ScanUpdated;
}
void ScanUpdated(Scan scan)
{
//clear old points
foreach(var oldPoint in pointList)
{
Destroy(oldPoint);
}
foreach (var sample in scan.Samples)
{
var position = sample.Distance * new Vector3(Mathf.Cos(Mathf.Deg2Rad * sample.Angle), 0, Mathf.Sin(Mathf.Deg2Rad * sample.Angle));
var point = Instantiate(PointPrefab, position, Quaternion.identity, transform);
pointList.Add(point);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment