4.6 新用户界面如何更改按钮图像? [英] 4.6 New UI How to change Button Image?

查看:25
本文介绍了4.6 新用户界面如何更改按钮图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索的所有内容均基于旧用户界面.

Everything I search is based on the old 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>("....");

我想更改事件的按钮图像.

I want to change the button image on an event.

推荐答案

已测试和工作.

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.

}

这篇关于4.6 新用户界面如何更改按钮图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆