using UnityEngine;
namespace NanoBrain.Unity.Braitenberg {
///
/// A sensor which can detect contacts with static GameObjects or Rigidbodies
///
[HelpURL("https://passer.life/documentation/nanobrain/Documentation/html/class_nano_brain_1_1_unity_1_1_braitenberg_1_1_touch_sensor.html")]
public class TouchSensor : Sensor {
///
/// Is the sensor touching something?
///
public bool touching { get; protected set; }
///
/// Returns the current touching state
///
/// 1.0 when touching something, 0.0 otherwise
protected override float SampleSensor() {
return touching ? 1 : 0;
}
private void OnTriggerEnter(Collider other) {
//Debug.Log($"{this.name} touch start");
touching = true;
}
private void OnTriggerExit(Collider other) {
//Debug.Log($"{this.name} touch END");
touching = false;
}
}
}