首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解析其他脚本中prefab(UILabel)的值

解析其他脚本中prefab(UILabel)的值
EN

Stack Overflow用户
提问于 2015-01-13 11:44:04
回答 1查看 335关注 0票数 0

我想知道怎样才能获得预置文件的价值。例如,我在场景中创建了一个ngui进度条,并显示了允许进度条位置的百分比。进度条是预置的,我希望使用'GetComponent‘访问其他脚本中百分比的值。

这是uiroot Strat()方法的脚本:

代码语言:javascript
复制
protected virtual void Start ()
{
    // Here - > Showing Null Exception

    UILabel uiLabel = GetComponent<UILabel> ();
    Debug.Log (uiLabel.text);
    // end

    UIOrthoCamera oc = GetComponentInChildren<UIOrthoCamera>();

    if (oc != null)
    {
        Debug.LogWarning("UIRoot should not be active at the same time as UIOrthoCamera. Disabling UIOrthoCamera.", oc);
        Camera cam = oc.gameObject.GetComponent<Camera>();
        oc.enabled = false;
        if (cam != null) cam.orthographicSize = 1f;
    }
    else Update();
}

这是UILabel (预置文件)的脚本:

代码语言:javascript
复制
public void SetCurrentPercent ()
{
    if (UIProgressBar.current != null)
        text = Mathf.RoundToInt(UIProgressBar.current.value * 100f) + "%";
    // I want to access this text!!!
    Debug.Log (text);
}

我怎样才能访问某个地方的“文本”?

在这两种情况下都会发生错误。

1.

代码语言:javascript
复制
Assets/NGUI/Scripts/UI/UIRoot.cs(151,64): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected
Assets/NGUI/Scripts/UI/UIRoot.cs(151,52): error CS1502: The best overloaded method match for `UnityEngine.Object.Instantiate(UnityEngine.Object)' has some invalid arguments
Assets/NGUI/Scripts/UI/UIRoot.cs(151,52): error CS1503: Argument `#1' cannot convert `object' expression to type `UnityEngine.Object'

2.

代码语言:javascript
复制
Assets/NGUI/Scripts/UI/UIRoot.cs(153,35): error CS0176: Static member `UILabel.value' cannot be accessed with an instance reference, qualify it with a type name instead
EN

回答 1

Stack Overflow用户

发布于 2015-01-19 07:43:35

抱歉反馈得太晚了。

我看到下面的错误。错误CS0029:无法隐式转换类型string' toUnityEngine.GameObject‘

我意识到我必须给父母的孩子打电话。Prefab是一个对象,它有我想要得到的组件的子对象。总之,我很容易就弄明白了。这是个很简单的问题。

这是下面的剧本。

代码语言:javascript
复制
<script>
UILabel UILabel = GameObject.Find ("third").GetComponentInChildren<UILabel> ();
print (UILabel.text);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27921380

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档