Unity changing GuiTexutre results null texure.

Hi, I am a very newb to unity like less than a month. I am having a problem changing guitexture of a guitexture. I have seen alot of questions and answers and have tried them. What I am doing is I have is a GuiTexture object referenced from my scene to the script. I have this piece of code in C#:

public GUITexture Sound;

void somefunction()
Sound.texture = Resources.Load(“mute”) as Texture2D; // tried using as Texture too

When somefunction() is run, the button disappears - meaning the guitexture is set to none, I checked it while in play mode through inspector.

Any help would be appreciated, thnx in advance.

Also a side question, any difference between using sprites or guiTexture as buttons ? (Bearing in mind the different resolutions of the screens)

Here you can see what the code does:

Screen capture - ce457f1e8e29f9ff5776e0a9288b6c90 - Gyazo

I’m not sure what you’re doing but I’m assuming that you’re having a speaker icon that gets switched to a muted one when there is no volume playing? I’ve written a script like such before and I will happily give you the code for it.

First you will need to have everything done before you actually can switch the 2 textures with one another, with this I mean is that you pre-add the 2 textures to the script in the inspector before even executing the code (if you haven’t)

Add these 2 variables

	public Texture mutedIcon;
	public Texture unmutedIcon;

And for my own code I had a slider which you could slide which would also change the icon according to how loud the sound/volume was if you’re after that add this variable

	public float hSliderValue = 0.0F;

Additional variables:
Boolean to determine wether the music was muted or not

public bool mutedMusic = false;

I haven’t done anything with resolution so you might have to change some of the code down here.
The OnGUI:

    	void OnGUI(){
    		if(GUI.Button (new Rect(40, 0, 40, 40), icon)){
    			mutedMusic = mutedMusic ? music.mute = false : music.mute = true;
    			hSliderValue = mutedMusic ? 0 : 10;
//wether the slider was on 0 or if the music is muted
    			if(mutedMusic || hSliderValue == 0){
    				icon = mutedIcon;
    				mutedMusic = true;
//if volume is higher than 0.1 basically
    			if(hSliderValue >= 0.1f){
    				icon = unmutedIcon;
    				music.mute = false;
    				mutedMusic = false;
//the slider that lets you control the volume
    		hSliderValue = GUI.HorizontalSlider(new Rect(0, 40, 100, 30), hSliderValue, 0.0f, 10.0f);
    		AudioListener.volume = hSliderValue/10.0f;

I’ve written the code quite some time ago so there might be some errors in it, if you need any more help you can ask, if not you can put this as an answer to your question and potentionally add a comment to it to make things clear that I haven’t made clear in my code x).