# playMaker

### Author Topic: Round Float Value  (Read 2979 times)

#### Andrew.Lukasik

• Full Member
• Posts: 134
##### Round Float Value
« on: September 04, 2011, 04: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)

Code: [Select]
`// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.// small additional action by Andrew Raphael Ĺukasikusing 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); } }}`
« Last Edit: September 05, 2011, 04:31:33 AM by Andrew_Raphael_Lukasik »

#### tobbeo

• 1.2 Beta
• Full Member
• Posts: 186
##### Re: Round Float Value
« Reply #1 on: September 04, 2011, 06:08:11 PM »
Interesting, thanks!

#### jeroenboumans

• Playmaker Newbie
• Posts: 2
##### Re: Round Float Value
« Reply #2 on: September 16, 2011, 12: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!

#### Andrew.Lukasik

• Full Member
• Posts: 134
##### Re: Round Float Value
« Reply #3 on: September 16, 2011, 03: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