MarkusKer
Member
Hello, i was trying to write some custom task to compare which enemy is the closest to the player but i am getting an stack overflow error.
Any Ideas?
using UnityEngine;
using BehaviorDesigner.Runtime;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace BehaviorDesigner.Runtime.Tasks.Unity.SharedVariables
{
[TaskCategory("Unity/SharedVariable")]
[TaskDescription("Returns success if the variable value is equal to the compareTo value.")]
public class CompareSharedFloatDistance : Conditional
{
public GameObject[] Swarm;
public float closest;
public List<float> myList = new List<float>();
public SharedFloat myIntVariable2;
public override TaskStatus OnUpdate()
{
Swarm = GameObject.FindGameObjectsWithTag("Enemy");
foreach (GameObject Climbing in Swarm)
{
if (Climbing.name == ("swarm"))
{
var test2 = Climbing.GetComponent<BehaviorTree>();
var myIntVariable1 = (SharedFloat)test2.GetVariable("Distance");
myList.Add(myIntVariable1.Value);
}
}
closest = myList.Min();
return myIntVariable2.Value.Equals(closest) ? TaskStatus.Success : TaskStatus.Failure;
}
}
}
Also i am wondering why the marked part of my behavior is only beeing executed once. How would i be able to check its value every now and then?
Any Ideas?
using UnityEngine;
using BehaviorDesigner.Runtime;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace BehaviorDesigner.Runtime.Tasks.Unity.SharedVariables
{
[TaskCategory("Unity/SharedVariable")]
[TaskDescription("Returns success if the variable value is equal to the compareTo value.")]
public class CompareSharedFloatDistance : Conditional
{
public GameObject[] Swarm;
public float closest;
public List<float> myList = new List<float>();
public SharedFloat myIntVariable2;
public override TaskStatus OnUpdate()
{
Swarm = GameObject.FindGameObjectsWithTag("Enemy");
foreach (GameObject Climbing in Swarm)
{
if (Climbing.name == ("swarm"))
{
var test2 = Climbing.GetComponent<BehaviorTree>();
var myIntVariable1 = (SharedFloat)test2.GetVariable("Distance");
myList.Add(myIntVariable1.Value);
}
}
closest = myList.Min();
return myIntVariable2.Value.Equals(closest) ? TaskStatus.Success : TaskStatus.Failure;
}
}
}
Also i am wondering why the marked part of my behavior is only beeing executed once. How would i be able to check its value every now and then?