2015-01-04 2 views
7

내가 검색 한 모든 것은 이전 UI를 기반으로합니다.4.6 새 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>("...."); 

을 시도했습니다.

답변

4

테스트 및 작동 중.

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. 

} 
관련 문제