RandomInt.cs 1019 B

123456789101112131415161718192021222324252627282930313233343536
  1. using UnityEngine;
  2. namespace BehaviorDesigner.Runtime.Tasks.Unity.Math
  3. {
  4. [TaskCategory("Unity/Math")]
  5. [TaskDescription("Sets a random int value")]
  6. public class RandomInt : Action
  7. {
  8. [Tooltip("The minimum amount")]
  9. public SharedInt min;
  10. [Tooltip("The maximum amount")]
  11. public SharedInt max;
  12. [Tooltip("Is the maximum value inclusive?")]
  13. public bool inclusive;
  14. [Tooltip("The variable to store the result")]
  15. public SharedInt storeResult;
  16. public override TaskStatus OnUpdate()
  17. {
  18. if (inclusive) {
  19. storeResult.Value = Random.Range(min.Value, max.Value + 1);
  20. } else {
  21. storeResult.Value = Random.Range(min.Value, max.Value);
  22. }
  23. return TaskStatus.Success;
  24. }
  25. public override void OnReset()
  26. {
  27. min.Value = 0;
  28. max.Value = 0;
  29. inclusive = false;
  30. storeResult.Value = 0;
  31. }
  32. }
  33. }