Join our Discord Channel
using UnityEngine;namespace HutongGames.PlayMaker.Actions{ [ActionCategory(ActionCategory.Math)] [Tooltip("Sets Provided Float Variable to a Provided Value based on the comparison of 2 Floats.")] public class FloatCompareSetValue : FsmStateAction { [RequiredField] public FsmFloat float1; [RequiredField] public FsmFloat float2; [RequiredField] public FsmFloat tolerance; [RequiredField] [Tooltip("Float Variable to Set to different outcome values")] public FsmFloat floatToChange; [Tooltip("Value to Set if Float 1 equals Float 2 (within Tolerance)")] public FsmFloat equal; [Tooltip("Value to Set if Float 1 is less than Float 2")] public FsmFloat lessThan; [Tooltip("Value to Set if Float 1 is greater than Float 2")] public FsmFloat greaterThan; public bool everyFrame; public override void Reset() { float1 = 0f; float2 = 0f; tolerance = 0f; floatToChange = 0f; equal = 0f; lessThan = 0f; greaterThan = 0f; everyFrame = false; } public override void OnEnter() { DoCompare(); if (!everyFrame) Finish(); } public override void OnUpdate() { DoCompare(); } void DoCompare() { if (Mathf.Abs(float1.Value - float2.Value) <= tolerance.Value) { floatToChange.Value = equal.Value; return; } if (float1.Value < float2.Value) { floatToChange.Value = lessThan.Value; return; } if (float1.Value > float2.Value) { floatToChange.Value = greaterThan.Value; return; } } public override string ErrorCheck() { return ""; } }}