your statment : if(Ambient1.mute = false) was assigning (re: you needed 2 ‘=’ but only had 1)
the first part set them false, so the next if statement, had it been written correctly, would have evaluated to true; you could have used “else” instead.
Ah i see! Thanks for your reply!
“Ambient1.mute = !Ambient1.mute;” is what i did before, but i had some errors and must have done some wrong with the code.
Now i works as it should do, thanks a lot!
I was aware of that “issue” you might face… hm…
Let’s see, so just have the one trigger on the more “inner side” always turn the sound on/mute off, and the more “outter portion” always turn it off? Make sure there’s a bit of space in between them, I guess, for good measure.
Yeah i have the On Trigger just a little inside the room in front of the door, And the Off trigger on the outside, the distance is enough so a player fits between the triggers.
But my code do not work, it doesnt unmute the audio
Well, I don’t know about the GameObject triggeron /Off…
That isn’t really required. If you really want to just have 1 script that you re-use, make a bool for On/Off - that’d be even easier.
Just change the code so if the tag is the player, mute = bool_variable
One will always turn it on and one always off.
Im trying to by manual clicking the bool mute the audio, but the bool keep getting checked on startand cant be unchecked.
What stupid error am i doing now?
CODE:
public class AmbientTrigger : MonoBehaviour
{
public AudioSource Ambient1;
public AudioSource Ambient2;
public bool MuteAudio;
void Update ()
{
if (MuteAudio = true)
{
Ambient1.mute = true;
Ambient2.mute = true;
}
}
}
Now you’ve changed it to Update instead of trigger. I don’t think that’s needed (or good for your situation)
You’re also assigning MuteAudio = true instead of == true
But going back to a previous post… I think you should have this:
public bool MuteAudio = false; // you'll have 2 scripts/objects and in the inspector of the one y ou want true, change this in the inspector
void OnTriggerEnter(Collider other) {
if(other.gameObject.CompareTag("Player") {
Ambient1.mute = MuteAudio;
Ambient2.mute = MuteAudio;
}
}
Just start the game with them muted (or set .mute = true) in Awake() - either way.
This setup will mean anytime they enter the trigger for muting, it will always mute - doesn’t care if it’s already muted or not… and if it’s the other trigger it will always unmute - again, regardless of whether it was or not before.
But the effect should be what you want.
Yes, it’s garbage free, since the ‘tag’ property requires creating a string that is passed from the C++ side. Where as passing a constant string from mono to the C++ creates no garbage since the C++ side is self managed.