[英]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.