I made a sprite to turn the audio off (button), but the script doesn’t work. I have problems with .active thing… Here’s the script:
#pragma strict
var audioIsOn : Sprite;
var audioIsOff : Sprite;
var Audio_Source : GameObject;
function Start ()
{
Audio_Source = GameObject.Find("homeAudio");
}
function OnMouseDown()
{
if(Audio_Source.activeInHierarchy == true) //also tried .active and .activeSelf
{
Audio_Source.SetActive(false);
// also tried: .active = false
// activeSelf = false and activeInHierachy = false
GetComponent(SpriteRenderer).sprite = audioIsOff;
}
if(Audio_Source.activeInHierarchy == false) //also tried .active and .activeSelf
{
Audio_Source.SetActive(true);
// also tried: .active = true
// activeSelf = true and activeInHierachy = true
GetComponent(SpriteRenderer).sprite = audioIsOn;
}
}