4.6 New UI How to change Button Image?

夙愿已清 提交于 2019-11-30 15:35:28

Tested and Working.

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.

}

Also you can use the properties of Button Component

http://docs.unity3d.com/Manual/script-Button.html

Specifically you can set the button's behavior based on events.

Example:

And then :

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!