2015-01-04 3 views
7

जो कुछ भी मैं खोजता हूं वह पुराने यूआई पर आधारित होता है।4.6 नया यूआई बटन छवि कैसे बदलें?

मैं निम्नलिखित

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. 

} 
3

इसके अलावा, आप बटन घटक

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

के गुणों का उपयोग विशेष रूप से आप घटनाओं पर आधारित बटन के व्यवहार सेट कर सकते हैं कर सकते हैं।

उदाहरण:

Empty properties

और फिर:

Button with sprite swap behavior on events

संबंधित मुद्दे