1
This commit is contained in:
29
Unity/Scripts/Sensor/RaySensor.cs
Normal file
29
Unity/Scripts/Sensor/RaySensor.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
namespace BITKit.Sensors
|
||||
{
|
||||
public class RaySensor : Sensor
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
public float distance;
|
||||
public override IEnumerable<Transform> Get() => detecteds;
|
||||
public override UniTask Excute()
|
||||
{
|
||||
if (Physics.Raycast(transform.position, transform.forward, out var rayhit, distance, detectLayer))
|
||||
{
|
||||
detecteds = new Transform[]{
|
||||
rayhit.transform
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
detecteds = new Transform[0];
|
||||
}
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
public override bool IsValid(Collider collider) => true;
|
||||
public override float GetDistance() => distance;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user