在unity3D中显示数学方程

时间:2014-07-22 18:02:14

标签: c# math unity3d

我想用它的GUI系统统一显示数学方程式。有办法吗?我在Unity中使用c#语言进行编程。如果我还可以使用c#代码显示数学symobls,对我来说会很有用。谢谢!

3 个答案:

答案 0 :(得分:3)

自2016年起,您可以使用TEXDraw以统一的方式呈现数学表达式。

答案 1 :(得分:1)

您可以使用GUI Text执行此操作。 http://docs.unity3d.com/Manual/class-GuiText.html

以下是关于如何执行此操作的不错的YouTube教程。 https://www.youtube.com/watch?v=_4nGKxZ7tVA

至于显示数学符号,你只需用刺痛中的符号格式化你的刺痛,然后在GUI文本中显示刺痛。

将以下内容放在C#脚本中并将脚本添加到GUIText对象,然后场景和文本将更新。

int a = 1;
int b = 2;
int c = a + b;
guiText.text = String.Format("{0} + {1} = {2}", a, b, c);

答案 2 :(得分:1)

您可以使用web api进行LaTeX数学运算并将其下载为纹理。一个例子:

enter image description here

如何在Unity3d中使用:

using UnityEngine;
using System.Collections;

public class Tester : MonoBehaviour {

    [SerializeField] string formula=@"\displaystyle\int_{-\infty}^{\infty}e^{-x^{2}}\;dx=\sqrt{\pi}";
    Texture texture=null;

    IEnumerator Start() {
        WWW www=new WWW("http://chart.apis.google.com/chart?cht=tx&chl="+formula);
        yield return www;
        texture=www.texture;
    }

    void OnGUI() {
        if(texture != null)
            GUI.DrawTexture(new Rect(0,0,texture.width,texture.height), texture);
    }
}

有许多实现,这里使用的是Google Charts API。不幸的是,它将在一年左右的时间内退役。

如果您不想要谷歌,那么另一种选择就是自定义托管的tex2im。

相关问题