PlayMaker Updates & Downloads > Share New Actions

Random Int with Increment Value

(1/1)

qholmes:
Incase this helps someone. As per a request.


--- Code: ---// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
// 'inclusiveMax' option added by MaDDoX (@brenoazevedo)
// 'incrementValue' option added by qholmes

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("Sets an Integer Variable to a random value between Min/Max.")]
public class RandomIntAdd : FsmStateAction
{
[RequiredField]
public FsmInt min;
[RequiredField]
public FsmInt max;
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmInt storeResult;
        [Tooltip("Should the Max value be included in the possible results?")]
        public bool inclusiveMax;
[Tooltip("Should the value be added to the Variable instead of replace it?")]
        public bool incrementValue;

public override void Reset()
{
min = 0;
max = 100;
storeResult = null;
// make default false to not break old behavior.
    inclusiveMax = false;
incrementValue = false;
}

public override void OnEnter()
{
           
var tmpValue = (inclusiveMax) ?
                Random.Range(min.Value, max.Value + 1) :
                Random.Range(min.Value, max.Value);
   
if (incrementValue)
storeResult.Value = storeResult.Value + tmpValue;
else
storeResult.Value = tmpValue;

            Finish();
}
}
}
--- End code ---

Dev_Sebas:
Thanks a again
Bye

Navigation

[0] Message Index

Go to full version