// Use this for initialization public void ActualizeEquation(string newEquationString) { if (this.equationString != newEquationString) { GameManager.GetCurrentCharacter().GetComponent <EquationScriptComponent>().OnStringChange(newEquationString); try { equation = new Text2AST.Equation(newEquationString, variables); List <Vector3> newlyCreatedTrajectory = new List <Vector3>(); float offset = (float)equation.With("x", 0).GetValue(); for (double x = 0; x < 30; x += 0.1) { newlyCreatedTrajectory.Add(new Vector3((float)x, (float)equation.With("x", x).GetValue() - offset, 49)); } createdTrajectory = newlyCreatedTrajectory; } catch (Text2AST.WrongEquationException) { Debug.Log("Wrong written equation"); equation = null; } catch (Text2AST.BadDefinedException) { Debug.Log("Bad defined equation"); equation = null; } catch (System.Exception ex) { Debug.Log("Unknown exception"); Debug.Log(ex.Message); equation = null; } equationString = newEquationString; } }
private float GetY(float x) { return((float)equation.With("x", x).GetValue()); }