【问题标题】:4.6 New UI How to change Button Image?4.6 新用户界面 如何更改按钮图像?
【发布时间】:2015-03-01 21:33:35
【问题描述】:
我搜索的所有内容都基于旧 UI。
我尝试了以下方法
button.image = Resource.Load<Image>("...");
button.GetComponent<Image>() = Resources.Load<Image>("....");
button.GetComponent<Button>().image = Resources.Load<Image>("....");
button.GetComponent<Image>().sprite = Resources.Load<Sprite>("....");
我想更改事件的按钮图像。
【问题讨论】:
标签:
c#
unity3d
unity3d-gui
【解决方案1】:
经过测试和工作。
public Sprite myImage;
public Button myBtn;
void Start(){
myImage = Resources.Load<Sprite>("BTNS"); // Make sure not to include the file extension
//Make sure it is added in the Inspector. Or reference it using GameObject.Find.
myBtn.image.sprite = myImage; // That is right, no need to GetComponent.
}