FloatClamp.cs 798 B

123456789101112131415161718192021222324252627
  1. using UnityEngine;
  2. namespace BehaviorDesigner.Runtime.Tasks.Unity.Math
  3. {
  4. [TaskCategory("Unity/Math")]
  5. [TaskDescription("Clamps the float between two values.")]
  6. public class FloatClamp : Action
  7. {
  8. [Tooltip("The float to clamp")]
  9. public SharedFloat floatVariable;
  10. [Tooltip("The maximum value of the float")]
  11. public SharedFloat minValue;
  12. [Tooltip("The maximum value of the float")]
  13. public SharedFloat maxValue;
  14. public override TaskStatus OnUpdate()
  15. {
  16. floatVariable.Value = Mathf.Clamp(floatVariable.Value, minValue.Value, maxValue.Value);
  17. return TaskStatus.Success;
  18. }
  19. public override void OnReset()
  20. {
  21. floatVariable = minValue = maxValue = 0;
  22. }
  23. }
  24. }