Mas*_*tro 5 unity-game-engine unity3d-gui
我搜索的所有内容都基于旧的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>("....");
Run Code Online (Sandbox Code Playgroud)
我想更改活动上的按钮图像.
经过测试和工作.
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.
}
Run Code Online (Sandbox Code Playgroud)