playMaker

Author Topic: FloatSubtract  (Read 2544 times)

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
    • View Profile
FloatSubtract
« on: April 10, 2011, 05: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;
}
}
}
« Last Edit: April 10, 2011, 05:24:44 PM by tobbeo »

MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • View Profile
    • FluidPlay Studios
Re: FloatSubtract
« Reply #1 on: April 11, 2011, 04:29:56 AM »
Way to go, Tobbeo! ;)
--
Breno "MaDDoX" Azevedo
@brenoazevedo

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
    • View Profile
Re: FloatSubtract
« Reply #2 on: April 11, 2011, 07:41:33 PM »
Thanks! :D

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3201
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: FloatSubtract
« Reply #3 on: April 12, 2011, 12: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! ;)

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
    • View Profile
Re: FloatSubtract
« Reply #4 on: April 12, 2011, 01: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.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3201
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: FloatSubtract
« Reply #5 on: April 12, 2011, 01:59:22 AM »
Will definitely include it - thanks!