例子:获取一个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; 这样才能正确的获取的到
时间: 2024-10-22 03:21:12