- Home /
Setting menu music
I'm building a game where, at the end of each level, a results screen is shown, with the game in the background. Once the screen is accessed (you fly into a trigger box), I want a victory tune to play. To do this, I have written the code to be as such:
using UnityEngine;
using System.Collections;
public class NewLevel : MonoBehaviour {
public Material otherSkybox;
private bool newlevel= false;
public GameObject camera;
public AudioClip victory;
void Start() {
newlevel = false;
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Player"){
newlevel = true;
}
if (newlevel== true){
RenderSettings.skybox = otherSkybox;
camera.audio.Play(victory);
transform.localPosition = new Vector3(0, 0, 0);
print(transform.localPosition.y);
}
}
}
The problem I have is however that I get the following compile error: The best overload match for "unityengine.audiosource.play(ulong)" has some invalid arguments. And that's strange, since I've basicaly copied the example in the unity documentation pages.
If I've answered your question could you please accept my answer.
Answer by lolzrofl · Nov 03, 2014 at 10:07 PM
Attach an AudioSource component to your game object and assign your music to it.
Then change victory to public AudioSource victory;
and attach the AudioSource component in the editor.
Lastly play the audio like this victory.Play();
Your answer
Follow this Question
Related Questions
.wav file not working 2 Answers
Audio Scripting 1 Answer
2017.1 and iOS music playback 0 Answers
Unity and music tracks - load track at certain point and fading tracks in and out 1 Answer