Instantiate.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. using UnityEngine;
  2. namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityGameObject
  3. {
  4. [TaskCategory("Unity/GameObject")]
  5. [TaskDescription("Instantiates a new GameObject. Returns Success.")]
  6. public class Instantiate : Action
  7. {
  8. [Tooltip("The GameObject that the task operates on. If null the task GameObject is used.")]
  9. public SharedGameObject targetGameObject;
  10. [Tooltip("The position of the new GameObject")]
  11. public SharedVector3 position;
  12. [Tooltip("The rotation of the new GameObject")]
  13. public SharedQuaternion rotation = Quaternion.identity;
  14. [SharedRequired]
  15. [Tooltip("The instantiated GameObject")]
  16. public SharedGameObject storeResult;
  17. public override TaskStatus OnUpdate()
  18. {
  19. storeResult.Value = GameObject.Instantiate(targetGameObject.Value, position.Value, rotation.Value) as GameObject;
  20. return TaskStatus.Success;
  21. }
  22. public override void OnReset()
  23. {
  24. targetGameObject = null;
  25. position = Vector3.zero;
  26. rotation = Quaternion.identity;
  27. }
  28. }
  29. }