Work an a priority system ish

Epidemic

New member
Basically, the idea is that this script will take the given list of objects gotten from a raycast in all four directions and decide what is more important for the ai to target. In this case, the player will take precedence over a wall or block, and if it finds neither it will set it automatically to a shrine object. However the target variable doesn't get set in my tree.

using UnityEngine;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;

public class PickTarget : Action
{

public SharedGameObjectList targs;

public SharedGameObject target;

private GameObject[] targets;
private bool loopComplete = false;

public SharedGameObject shrine;

public override void OnStart()
{
targets = targs.Value.ToArray();
loopComplete = false;
}

public override TaskStatus OnUpdate()
{
for(int t = 0; t < targets.Length; t++)
{
GameObject tmp = targets[t];
switch (tmp.tag)
{
case "Player":
target.Value = tmp;
break;
case "Block":
if (target == null)
{
target.Value = tmp;
}
break;
default:
target.Value = shrine.Value;
break;
}
}

if (target == null)
{
target.Value = shrine.Value;
}
return TaskStatus.Success;
}

}
 

Justin

Administrator
Staff member
It looks like you are correctly calling the target value:

Code:
target.Value = shrine.Value;
Are you saying that after this line is set your shared variable isn't being set?
 

Justin

Administrator
Staff member
Unfortunately due to my support load I'm not able to debug custom scripts but I recommend placing a breakpoint in your task and stepping through the method. This will allow you to determine what isn't being set correctly.
 

Epidemic

New member
So I had rebuilt it and it worked

this is what I did:

public SharedGameObjectList targs;

public SharedGameObject target;

private GameObject[] targets;
private bool loopComplete = false;

public SharedGameObject shrine;

public override void OnStart()
{
targets = targs.Value.ToArray();
loopComplete = false;
}

public override TaskStatus OnUpdate()
{

for (int i = 0; i < targets.Length; i++)
{
if (target.Value != null)
{
if (targets.tag == "Player")
{
target.Value = targets;
}
if(targets.tag == "Block")
{
if(target.Value.tag != "Player")
{
target.Value = targets;
}
}
}
else
{
if (targets.tag == "Player" || targets.tag == "Block")
{
target.Value = targets;
}
else
{
target.Value = shrine.Value;
}
}
}

return TaskStatus.Success;
}
 
Top