我想知道怎样才能获得预置文件的价值。例如,我在场景中创建了一个ngui进度条,并显示了允许进度条位置的百分比。进度条是预置的,我希望使用'GetComponent‘访问其他脚本中百分比的值。
这是uiroot Strat()方法的脚本:
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 (预置文件)的脚本:
public void SetCurrentPercent ()
{
if (UIProgressBar.current != null)
text = Mathf.RoundToInt(UIProgressBar.current.value * 100f) + "%";
// I want to access this text!!!
Debug.Log (text);
}我怎样才能访问某个地方的“文本”?
在这两种情况下都会发生错误。
1.
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.
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发布于 2015-01-19 07:43:35
抱歉反馈得太晚了。
我看到下面的错误。错误CS0029:无法隐式转换类型string' toUnityEngine.GameObject‘
我意识到我必须给父母的孩子打电话。Prefab是一个对象,它有我想要得到的组件的子对象。总之,我很容易就弄明白了。这是个很简单的问题。
这是下面的剧本。
<script>
UILabel UILabel = GameObject.Find ("third").GetComponentInChildren<UILabel> ();
print (UILabel.text);https://stackoverflow.com/questions/27921380
复制相似问题