diff options
Diffstat (limited to 'Client/Assets/Behavior Designer/Runtime/Basic Tasks/Rigidbody2D/GetPosition.cs')
-rw-r--r-- | Client/Assets/Behavior Designer/Runtime/Basic Tasks/Rigidbody2D/GetPosition.cs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/Client/Assets/Behavior Designer/Runtime/Basic Tasks/Rigidbody2D/GetPosition.cs b/Client/Assets/Behavior Designer/Runtime/Basic Tasks/Rigidbody2D/GetPosition.cs new file mode 100644 index 00000000..6b1c1c53 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Basic Tasks/Rigidbody2D/GetPosition.cs @@ -0,0 +1,50 @@ +using UnityEngine;
+
+namespace BehaviorDesigner.Runtime.Tasks.Basic.UnityRigidbody2D
+{
+ [TaskCategory("Basic/Rigidbody2D")]
+ [TaskDescription("Stores the position of the Rigidbody2D. Returns Success.")]
+ public class GetPosition : Action
+ {
+ [Tooltip("The GameObject that the task operates on. If null the task GameObject is used.")]
+ public SharedGameObject targetGameObject;
+ [Tooltip("Can the target GameObject be empty?")]
+ public SharedBool allowEmptyTarget;
+ [Tooltip("The velocity of the Rigidbody2D")]
+ [RequiredField]
+ public SharedVector2 storeValue;
+
+ private Rigidbody2D rigidbody2D;
+ private GameObject prevGameObject;
+
+ public override void OnStart()
+ {
+ if (!allowEmptyTarget.Value) {
+ var currentGameObject = GetDefaultGameObject(targetGameObject.Value);
+ if (currentGameObject != prevGameObject) {
+ rigidbody2D = currentGameObject.GetComponent<Rigidbody2D>();
+ prevGameObject = currentGameObject;
+ }
+ }
+ }
+
+ public override TaskStatus OnUpdate()
+ {
+ if (rigidbody2D == null) {
+ Debug.LogWarning("Rigidbody2D is null");
+ return TaskStatus.Failure;
+ }
+
+ storeValue.Value = rigidbody2D.position;
+
+ return TaskStatus.Success;
+ }
+
+ public override void OnReset()
+ {
+ targetGameObject = null;
+ allowEmptyTarget = false;
+ storeValue = Vector2.zero;
+ }
+ }
+}
\ No newline at end of file |