- Home /
Question by
Hat Origins · Jul 04, 2015 at 06:52 PM ·
c#uispriteimage
How to make a UI image change sprite through a script that is not attached to the UI image itself
I'm trying to get a sprite of a UI image to change when i click on it. Currently what happens is that after i use Application.LoadLevel(0) i can no longer change the sprite of the image.`
public Sprite MusicOn;
public Sprite MusicOff;
public Image image;
public void OnClickMute ()
{
switch (PlayerPrefs.GetInt("Mute"))
{
case 1:
PlayerPrefs.SetInt ("Mute", 2);
image.sprite = MusicOn;
audio.mute = false;
break;
case 2:
PlayerPrefs.SetInt ("Mute", 1);
image.sprite = MusicOff;
audio.mute = true;
break;
}
}`
What i have noticed is that after the Application.LoadLevel(0) occurs the OnClick event says its missing.
So basically this works fine the first time, however it breaks after reloading
Comment
Is your image set to not destroy itself when the level loads?