using BehaviorDesigner.Runtime.Tasks;
using UnityEngine;
namespace BehaviourTree.Brain
{
public class LocateTarget : Action
{
public float Fov;
public float CheckRadius;
public LayerMask TargetMask;
public Bot Bot;
public SharedTarget Target;
public override TaskStatus OnUpdate()
{
var foundTarget = FindTarget(CheckRadius, TargetMask);
if (foundTarget == null) return TaskStatus.Failure;
var eye = new Eye(Fov, Bot.transform);
if (eye.InSight(foundTarget) == false) return TaskStatus.Failure;
Target.Value = foundTarget;
return TaskStatus.Success;
}
private SomeTarget FindTarget(float radius, LayerMask mask)
{
var results = new Collider[64];
SomeTarget target = null;
if (Physics.OverlapSphereNonAlloc(Bot.transform.position, radius, results, mask) == 0) return target;
foreach (var collider in results)
{
if (collider == null) break;
if (collider.TryGetComponent(out SomeTarget found) == false) continue;
target = found;
break;
}
return target;
}
}
}
Да и спотыкаться лучше ему самому
и улучшать код
foreach (GameObject obj in _botsee_cs.GetObjectThatISee())
{
if (obj.GetComponent<IHealth>() != null)
{
if (obj != gameObject)
{
if (obj.GetComponent<IHealth>() != null)
{
if (obj.GetComponent<IHealth>().GetWarSide() != _health.GetWarSide())
{
return obj;
}
}
}
}
}
public class Cash1
{
private float _value;
public Cash1(float value)
{
_value = value;
}
public override string ToString() => $"${_value}";
}
public class Cash2
{
private float _value;
public Cash2(float startValue)
{
_value = startValue;
}
public void SetValue(float value)
{
_value = value;
}
public override string ToString() => $"${_value}";
}
public class Cash3
{
private float _value = 0;
public void SetValue(float value)
{
_value = value;
}
public float GetValue() => _value;
public override string ToString() => $"${_value}";
}