34 lines
962 B
C#

using UnityEngine;
namespace NanoBrain.Unity.Braitenberg {
/// <summary>
/// A sensor which can detect contacts with static GameObjects or Rigidbodies
/// </summary>
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;
}
}
}