Sensors is a Unity library providing various 2D and 3D sensors to detect objects within the game environment. These sensors can be particularly useful for AI development.
Each sensor type is available in both 2D and 3D and operates similarly
Property | Type | Description |
---|---|---|
Auto Update Sensor | bool | Enables automatic sensor updates. |
Ignore | GameObject[] | Ignores specified objects. |
Check Visibility | bool | Checks if detected objects are visible. |
Scan Layer | LayerMask | Defines the layer of detectable objects. |
Obstruction Layer | LayerMask | Specifies the layer obstructing visibility checks. |
Scan Rays | int | Number of rays used for visibility checks. |
Visibility | float (0-1) | Percentage of rays needed to detect an object for visibility. |
OnEnter | UnityEvent(GameObject) | Triggered when an object enters the sensor's range. |
OnStay | UnityEvent(GameObject) | Triggered when an object stays within the sensor's range. |
OnExit | UnityEvent(GameObject) | Triggered when an object exits the sensor's range. |
RaySensor sensor = GetComponent<RaySensor>();
GameObject[] detectedObjects = sensor.DetectedObjects;
RaySensor sensor = GetComponent<RaySensor>();
sensor.SensorUpdate();
RaySensor
RaySensor2D
Uses a single ray to detect objects.
Property | Type | Description |
---|---|---|
Distance | Float | Range of the sensor. |
RangeSensor
RangeSensor2D
Uses a sphere to detect objects.
Property | Type | Description |
---|---|---|
Range | Float | Range of the sensor. |
ViewSensor
ViewSensor2D
Uses a cone to detect objects.
Property | Type | Description |
---|---|---|
Distance | Float | Range of the sensor. |
Angle | Float | Angle of the sensor. |
TriggerSensor
TriggerSensor2D
Uses a trigger collider to detect objects. The trigger collider component must be attached to the same GameObject as the sensor.
Download the latest release and import the package into your Unity project.
https://github.com/DerKekser/unity-sensors.git?path=Assets/Kekser/Sensors
This library is under the MIT License.