Created
December 28, 2019 00:58
-
-
Save cyberfox/83509cdf9e2165e2635c13608c4a9ce6 to your computer and use it in GitHub Desktop.
Allows setting Behavior Designer variables on a GameObject as a Task.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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