Hi,
ok, I fixed it, basically the logic was right, but many issues and bug int he code where preventing it to work properly, let me explain each one of them:
maxExclusivePlaymaker = maxExclusivePlaymaker.Value;
here you assign the value of the property maxExclusivePlaymaker to itself, so the FsmFloat is now corrupted, you should never do that, but I think here it's a typo or bad copy paste.
outcome.Value = Random.Range (min, newMax);
you assign an intermediate result to the FsmFloat accepting the final result, you should never do that, always store the result when you know this is the final one. because in your case, your function DoMath() returns the final result, but your code doesn't use it to store the DoMath() result in outcome so you never have the final result, only the intermediate one.
Please find the corrected version:
Bye,
Jean
// Custom Action by DumbGameDev
// www.dumbgamedev.com
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Custom")]
[Tooltip("Find random float between two values but excluding a specific range")]
public class randomFloatExclusion : FsmStateAction
{
[RequiredField]
[TitleAttribute("Float Min")]
public FsmFloat minPlaymaker;
[RequiredField]
[TitleAttribute("Float Max")]
public FsmFloat maxPlaymaker;
[RequiredField]
[TitleAttribute("Float Min Exclusive")]
public FsmFloat minExclusivePlaymaker;
[RequiredField]
[TitleAttribute("Float Max Exclusive")]
public FsmFloat maxExclusivePlaymaker;
[TitleAttribute("Returned Value")]
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmFloat outcome;
[Tooltip("Repeat every frame")]
public bool everyFrame;
private float min;
private float max;
private float maxExclusive;
private float minExclusive;
float result;
public override void Reset()
{
everyFrame = false;
min = 0;
max = 0;
minExclusive = 0;
maxExclusive = 0;
outcome = null;
minPlaymaker = null;
maxPlaymaker = null;
minExclusivePlaymaker = null;
maxExclusivePlaymaker = null;
}
public override void OnEnter()
{
DoMath();
if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
DoMath();
}
void DoMath()
{
min = minPlaymaker.Value;
max = maxPlaymaker.Value;
minExclusive = minExclusivePlaymaker.Value;
maxExclusive = maxExclusivePlaymaker.Value;
var excluded = maxExclusive - minExclusive;
var newMax = max - excluded;
result= Random.Range (min, newMax);
outcome.Value = result > minExclusive ? result + excluded : result;
}
}
}