Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: Andrew.Lukasik on September 04, 2011, 07:17:12 PM

Title: Round Float Value
Post by: Andrew.Lukasik on September 04, 2011, 07:17:12 PM
FloatRound.cs

Simple action to round float variables using Mathf.Round

EXAMPLE:
source Float: <23.2463462>
result Float: <23>

Description: Returns f rounded to the nearest integer. If the number ends in .5 so it is halfway between two integers, one of which is even and the other odd, the even number is returned.
(documentation) (http://unity3d.com/support/documentation/ScriptReference/Mathf.Round.html)

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
// small additional action by Andrew Raphael Łukasik

using UnityEngine;
using System.Collections;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("Rounds Float Variable.")]
public class FloatRound : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmFloat floatVariable;
public bool everyFrame;

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

public override void OnEnter()
{
floatVariable.Value = Mathf.Round(floatVariable.Value);

if (!everyFrame)
Finish();
}

public override void OnUpdate()
{
floatVariable.Value = Mathf.Round(floatVariable.Value);
}
}
}
Title: Re: Round Float Value
Post by: tobbeo on September 04, 2011, 09:08:11 PM
Interesting, thanks!
Title: Re: Round Float Value
Post by: jeroenboumans on September 16, 2011, 03:20:15 AM
I'm working on a setup for a system that controls a temperature-unit. By pressing on different buttons the temperature changes (raising/decreasing). When the animation of the temperature plays the variable of the temperature is a non-rounded number. I would like to use this script but I don't really know how. When I use the Playmaker acion called 'Add Script' this script is not listed in it. Any tips?

Thnx!
Title: Re: Round Float Value
Post by: Andrew.Lukasik on September 16, 2011, 06:33:02 AM
Hi
Place this script somewhere in your \PlayMaker\Actions\ folder.
http://hutonggames.com/playmakerforum/index.php?action=dlattach;topic=662.0;attach=220

After doing that this action will be accessible via Playmaker's Action Browser ("Math" cathegory).

Greetings
Andrew