【问题标题】:Move label from one position to another in unity when the game is running游戏运行时将标签从一个位置统一移动到另一个位置
【发布时间】:2015-04-23 15:19:19
【问题描述】:

我正在 Unity 中制作一个简单的 2D 游戏。 我有两个标签,一个显示当前分数,另一个显示高分。我可以在游戏运行时将这些标签从一个位置移动到另一个位置吗?我想要一个“跳入”效果。希望大家能帮忙。

    public void ShowEndScore(Font font, float coins, int highscore)
    {
        GUIStyle style = new GUIStyle();
        style.fontSize = 150;
        style.fontStyle = FontStyle.Bold;
        style.normal.textColor = Color.yellow;
        style.alignment = TextAnchor.UpperCenter;
        style.font = font;


        GUI.Label (new Rect (Screen.width / 2 - 50, Screen.height / 2 - 50,     100, 50), "Your score: "+ coins, style);
        GUI.Label (new Rect (Screen.width / 2 - 50, Screen.height / 2, 100, 50), "Highscore: "+ highscore, style);
    } 

【问题讨论】:

  • 您尝试过什么来完成此任务,但没有成功?从您的代码中,我们只能收集到您创建了两个标签。
  • @EBrown 我还没有尝试过,因为我不知道如何 - 抱歉

标签: c# unity3d label 2d


【解决方案1】:

您使用的是哪个版本的 Unity?

我建议使用 4.6 UI 系统(所以使用 unity 4.6 或更高版本),只需通过脚本更改文本的位置,甚至为“跳转”设置动画。

您可以在此处找到有关新 UI 和动画等的精彩教程:

http://www.raywenderlich.com/78675/unity-new-gui-part-1

希望对你有帮助:)

【讨论】:

  • 我不使用 UI 系统的原因是它没有“标签”而只有“文本”——我想。出于某种原因,我无法根据需要增加“文本”的大小,我可以使用“标签”
  • 如果您在编辑器中添加文本,请按“t”查看文本矩形,然后您可以将其放大到您想要的大小。 ;)
  • np :) 祝你的游戏好运
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-07
  • 2017-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多