SetLayer.cs 835 B

123456789101112131415161718192021222324252627
  1. using UnityEngine;
  2. namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityLayerMask
  3. {
  4. [TaskCategory("Unity/LayerMask")]
  5. [TaskDescription("Sets the layer of a GameObject.")]
  6. public class SetLayer : Action
  7. {
  8. [Tooltip("The GameObject to set the layer of")]
  9. public SharedGameObject targetGameObject;
  10. [Tooltip("The name of the layer to set")]
  11. public SharedString layerName = "Default";
  12. public override TaskStatus OnUpdate()
  13. {
  14. var currentGameObject = GetDefaultGameObject(targetGameObject.Value);
  15. currentGameObject.layer = LayerMask.NameToLayer(layerName.Value);
  16. return TaskStatus.Success;
  17. }
  18. public override void OnReset()
  19. {
  20. targetGameObject = null;
  21. layerName = "Default";
  22. }
  23. }
  24. }