Или все должно быть как в примере с помощью функции Get() и функции Set()?
public class Document
{
public string Text { get; set; }
}
public class Human
{
public void ReadDocument(Document document)
{
Debug.Log(document.Text);
}
}
public class Document
{
private readonly string _text;
public Document(string text)
{
_text = text;
}
public void Print()
{
Debug.Log(_text);
}
}
public class Human
{
public void ReadDocument(Document document)
{
document.Print();
}
}
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;
}
}
}
}
}
Тебе и не надо экспериментировать, есть конвенции, следуй им:
https://docs.microsoft.com/en-us/dotnet/csharp/fun...
https://github.com/dotnet/runtime/blob/main/docs/c...