GetAxisRaw.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using UnityEngine;
  2. namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityInput
  3. {
  4. [TaskCategory("Unity/Input")]
  5. [TaskDescription("Stores the raw value of the specified axis and stores it in a float.")]
  6. public class GetAxisRaw : Action
  7. {
  8. [Tooltip("The name of the axis")]
  9. public SharedString axisName;
  10. [Tooltip("Axis values are in the range -1 to 1. Use the multiplier to set a larger range")]
  11. public SharedFloat multiplier;
  12. [RequiredField]
  13. [Tooltip("The stored result")]
  14. public SharedFloat storeResult;
  15. public override TaskStatus OnUpdate()
  16. {
  17. var axisValue = Input.GetAxis(axisName.Value);
  18. // if variable set to none, assume multiplier of 1
  19. if (!multiplier.IsNone) {
  20. axisValue *= multiplier.Value;
  21. }
  22. storeResult.Value = axisValue;
  23. return TaskStatus.Success;
  24. }
  25. public override void OnReset()
  26. {
  27. axisName = "";
  28. multiplier = 1.0f;
  29. storeResult = 0;
  30. }
  31. }
  32. }