GetRandomString.cs 737 B

12345678910111213141516171819202122232425262728
  1. using UnityEngine;
  2. namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityString
  3. {
  4. [TaskCategory("Unity/String")]
  5. [TaskDescription("Randomly selects a string from the array of strings.")]
  6. public class GetRandomString : Action
  7. {
  8. [Tooltip("The array of strings")]
  9. public SharedString[] source;
  10. [Tooltip("The stored result")]
  11. [RequiredField]
  12. public SharedString storeResult;
  13. public override TaskStatus OnUpdate()
  14. {
  15. storeResult.Value = source[Random.Range(0, source.Length)].Value;
  16. return TaskStatus.Success;
  17. }
  18. public override void OnReset()
  19. {
  20. source = null;
  21. storeResult = null;
  22. }
  23. }
  24. }