例子:获取一个TEXT组件
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class SilderText : MonoBehaviour
{
public Slider slider;
Text mytext;
// Update is called once per frame
public void UpdateText ()
{
mytext = gameObject.GetComponent<Text>();
mytext.text = slider.value.ToString();
}
}
在头文件里必须加上 using UnityEngine.UI; 这样才能正确的获取的到
原文地址:http://5152481.blog.51cto.com/5142481/1592075