Hi,
I search how to change texture of a GUITexture. I found many replies on the forum but all are outdated or just not working .
It’s a simple button on/off for playing music.
My code at the moment :
public class ToggleSound : MonoBehaviour {
int sound = 1;
public GUITexture Music_on;
public GUITexture Music_off;
void savePref(int sound){
PlayerPrefs.SetInt("music", sound);
}
void getPref(){
PlayerPrefs.GetInt("music");
}
void OnMouseDown(){
if (sound == 1){
GameObject.Find("Space").audio.Stop();
sound = 0;
savePref(sound);
GameObject.Find("musicSwitch").guiTexture.texture = Music_off; // error here
} else {
GameObject.Find("Space").audio.Play();
sound = 1;
savePref(sound);
GameObject.Find("musicSwitch").guiTexture.texture = Music_on; // error here
}
}
}
The error :
Assets/Menu/ToggleSound.cs(23,67): error CS0029: Cannot implicitly convert type UnityEngine.GUITexture' to
UnityEngine.Texture’
L 23 : GameObject.Find(“musicSwitch”).guiTexture.texture = Music_off;
Thanks