简体   繁体   English

游戏运行时,将标签从一个位置统一移动到另一位置

[英]Move label from one position to another in unity when the game is running

I'm making a simple 2D game in Unity. 我正在Unity中制作一个简单的2D游戏。 I have two labels, one that shows current score and another highscore. 我有两个标签,一个显示当前得分,另一个显示高分。 Can I move these label form one position to another when the game is running? 游戏运行时,我可以将这些标签从一个位置移动到另一个位置吗? I want a "jump-in" effect. 我想要一个“跳入”效果。 Hope you guys can help. 希望你们能提供帮助。

    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);
    } 

Which version of Unity are you using? 您正在使用哪个版本的Unity?

I would recommend to use the 4.6 UI system (so use unity 4.6 or above) and just change the position of the text via a script or even animate the "jump-in". 我建议使用4.6 UI系统(因此使用4.6或更高版本),只需通过脚本更改文本的位置,甚至可以为“跳转”设置动画。

You can find a nice tutorial about the new UI and animation with it etc here: 您可以在此处找到有关新UI和动画的不错的教程:

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

I hope that helps :) 希望对您有所帮助:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#中的Vector3.Lerp不能平稳地移动,只是从一个位置捕捉到另一个位置 - Vector3.Lerp in C# in unity doesn't move smoothly just snaps from one position to another 将玩家位置发送给其他玩家,使用Unity Photon将他移动到多玩家游戏中 - Send player position to another player to move him in multi player game using Unity Photon 如何让一个游戏对象的 x 位置等于另一个对象的 x 位置? (2D Unity 游戏) - How do I get one game objects x position to equal another objects x position? (2D Unity Game) 如何在 Unity Hololens 中将文件从一个目录移动到另一个目录 - How to move files from one directory to another in Unity Hololens 如何让玩家从一个 x position 移动到另一个? - How to get player to move from one x position to another? Unity-如何将动画从一个游戏对象应用于另一个装备的游戏对象? - Unity - How do I apply an animation from one game object to another rigged game object? 游戏运行时从其中一个相机游戏对象截取屏幕截图,然后是 output - Taking a screenshot from one of the Camera GameObjects when the game is running and then output Unity GUI标签位置 - Unity GUI Label Position 在统一中,如何将一个输入字段文本或 label 文本从一个传输到另一个 class 输入字段文本或 label 文本? - In unity how to transfer one input field text or label text from one to another class input field text or label text? Unity 基于鼠标(拖动)position 在另一个 object 的轨道上移动 object - Unity move object in orbit of another object based on mouse(drag) position
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM