LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

This version of Unity is unsupported.

ExpressionEvaluator.Evaluate

public static T Evaluate(string expression);

Parameters

expressionA string containing a mathematical expression (e.g. "4 + 3").

Returns

T The result of the evaluation (0 for invalid expressions).

Description

Evaluates a math expression and returns the result as a float or int.

If the expression is invalid or cannot be evaluated properly, then the result will be 0.