统一4.6 UI按钮更改文本 [英] Change text of Unity 4.6 UI button

查看:266
本文介绍了统一4.6 UI按钮更改文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想了好几天都没有成功。如何更改使用C#脚本统一4.6按钮的文本?任何建议都AP preciated。

I've been trying for days without success. How do I change the text of a Unity 4.6 button using C# script? Any suggestions are appreciated.

推荐答案

创建一个脚本,并将其添加到您的UIButton
你应该添加引用Unity.UI

Create a script and add it to your UIButton you should add the reference Unity.UI

using UnityEngine.UI;

然后声明一个变量

then declare a variable

Text yourButtonText;

在开始把这个功能

void Start()
{
    yourButtonText = transform.FindChild("Text").GetComponent<Text>();
}

然后当你想改变你的文字添加此

then when you want to change your text add this

yourButtonText.text = "i am a button!";

如果您需要申请更多的修改,请访问<一个href=\"http://docs.unity3d.com/ScriptReference/UI.Text.html\">http://docs.unity3d.com/ScriptReference/UI.Text.html

if you need to apply more modifications visit http://docs.unity3d.com/ScriptReference/UI.Text.html

[与标签版本]

添加此引用

using System.Collections.Generic;

public Text[] yourButtonTextArrays = new Text[15];

void Start()
{
    for (int i = 0; i < 15; i++ )
    {
        yourButtonTextArrays[i] = GameObject.FindGameObjectWithTag("Button" + i+1.ToString()).transform.FindChild("Text").GetComponent<Text>();
    }
}

然后当你想改变你的文字添加此

then when you want to change your text add this

yourButtonTextArrays[yourButtonNumber].text = "i am a button from the array of buttons";

这篇关于统一4.6 UI按钮更改文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆