35 lines
1.1 KiB
C#

using UnityEngine;
namespace NanoBrain.Unity.Braitenberg {
/// <summary>
/// A sensor which can detect contacts with static GameObjects or Rigidbodies
/// </summary>
[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 {
/// <summary>
/// Is the sensor touching something?
/// </summary>
public bool touching { get; protected set; }
/// <summary>
/// Returns the current touching state
/// </summary>
/// <returns>1.0 when touching something, 0.0 otherwise</returns>
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;
}
}
}