GetComponent.cs 1008 B

12345678910111213141516171819202122232425262728293031
  1. using UnityEngine;
  2. namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityGameObject
  3. {
  4. [TaskCategory("Unity/GameObject")]
  5. [TaskDescription("Returns the component of Type type if the game object has one attached, null if it doesn't. Returns Success.")]
  6. public class GetComponent : 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 type of component")]
  11. public SharedString type;
  12. [Tooltip("The component")]
  13. [RequiredField]
  14. public SharedObject storeValue;
  15. public override TaskStatus OnUpdate()
  16. {
  17. storeValue.Value = GetDefaultGameObject(targetGameObject.Value).GetComponent(type.Value);
  18. return TaskStatus.Success;
  19. }
  20. public override void OnReset()
  21. {
  22. targetGameObject = null;
  23. type.Value = "";
  24. storeValue.Value = null;
  25. }
  26. }
  27. }