Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: tobbeo on April 10, 2011, 08:21:23 PM

Title: FloatSubtract
Post by: tobbeo on April 10, 2011, 08:21:23 PM
Very simple "FloatSubtract" action as requested by fis.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
// Simple custom action by Tobbe Olsson - www.tobbeo.net

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("Adds a value to a Float Variable.")]
public class FloatSubtract : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmFloat floatVariable;
[RequiredField]
public FsmFloat subtract;
public bool everyFrame;
public bool perSecond;

public override void Reset()
{
floatVariable = null;
subtract = null;
everyFrame = false;
perSecond = false;
}

public override void OnEnter()
{
DoFloatSubtract();

if (!everyFrame)
Finish();
}

public override void OnUpdate()
{
DoFloatSubtract();
}

void DoFloatSubtract()
{
if (!perSecond)
floatVariable.Value -= subtract.Value;
else
floatVariable.Value -= subtract.Value * Time.deltaTime;
}
}
}
Title: Re: FloatSubtract
Post by: MaDDoX on April 11, 2011, 07:29:56 AM
Way to go, Tobbeo! ;)
Title: Re: FloatSubtract
Post by: tobbeo on April 11, 2011, 10:41:33 PM
Thanks! :D
Title: Re: FloatSubtract
Post by: Alex Chouls on April 12, 2011, 03:21:57 AM
This is great! I'm excited to see people helping each other out with actions - leaves us with more time to work on core features! ;)
Title: Re: FloatSubtract
Post by: tobbeo on April 12, 2011, 04:43:56 AM
This is great! I'm excited to see people helping each other out with actions - leaves us with more time to work on core features! ;)

Maybe this goes without saying, and I just modified one of your actions but feel free to include it in the release. It's a very basic, but handy addition.
Title: Re: FloatSubtract
Post by: Alex Chouls on April 12, 2011, 04:59:22 AM
Will definitely include it - thanks!