Change Music Problem

void OnTriggerEnter()
if (!alreadyPlayed)
audio.PlayOneShot(SoundToPlay, Volume);
alreadyPlayed = true;

Work fine for me , until i want make it automatically change to a new bgm , so i try new code

void OnTriggernEnter(Collider other){
		if(other.tag == "player")
			BGMS.ChangeBGM (newtrack);

The problem start , it not even changing music nor give a music …
here my audio manager

public void ChangeBGM(AudioClip music){

	if ( ==

	BGM.Stop ();
	BGM.clip = music;
	BGM.Play ()

I just want when i pass a game object , it change BGM … can anyone help me :smiley: ~?

The code looks okay to me. I’d put some Debug.Logs in there to find out where the problem happens. I can think of some mistakes that one couldn’t see in your code.

  • The object entering the Trigger does not have the tag “player”, but “Player”, for example. Use CompareTag to avoid this mistake.
  • newtrack is null for some reason.
  • The AudioClips have the same name. You could compare them directly instead of comparing their names.
  • Edit: The extra ‘n’ in ‘OnTriggerEnter’ that GamerJoHo mentioned.