Skip to content

Instantly share code, notes, and snippets.

@cyberfox
Created December 28, 2019 00:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyberfox/83509cdf9e2165e2635c13608c4a9ce6 to your computer and use it in GitHub Desktop.
Save cyberfox/83509cdf9e2165e2635c13608c4a9ce6 to your computer and use it in GitHub Desktop.
Allows setting Behavior Designer variables on a GameObject as a Task.
using System;
namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityGameObject
{
[TaskCategory("Unity/GameObject")]
[TaskDescription("Sets a Behavior Designer variable on a GameObject. Returns success.")]
public class SetBehaviorVariable : Action
{
[Tooltip("The GameObject that the task operates on. If null the task GameObject is used.")]
public SharedGameObject TargetGameObject;
[Tooltip("The name of the variable to set.")]
public String VariableToSet;
[Tooltip("The GameObject to set the variable to.")]
public SharedGameObject ValueGameObject;
public override TaskStatus OnUpdate()
{
var behaviorTree = TargetGameObject.Value.GetComponent<BehaviorTree>();
behaviorTree.SetVariableValue(VariableToSet, ValueGameObject);
return TaskStatus.Success;
}
public override void OnReset()
{
TargetGameObject = null;
VariableToSet = "";
ValueGameObject = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment