How do i get my fu... sound to play when i die? Im a complete beginner heeelp ;) #pragmastrictforlife Thanks Alot
pragma strict
mport UnityEngine.SceneManagement ; //ignore
var maxFallDistance = -10 ; //ignore
var Ernst1 : AudioClip ; //Tried both AudioCLip and AudioSource
function Update () { if (transform.position.y <= maxFallDistance) //ignore {
GameMaster.currentScore = 0; //ignore SceneManager.LoadScene("banisch 1") ; //ignore Ernst1.Play(); //this little fucker. i get "play is not a member of Unityblabla.AudioClip" i've tried alot of different thigns but cant get it to work, i really have no idea }
}
Answer by KoenigX3 · Jan 13, 2017 at 05:02 PM
First, be sure to assign the 'death sound' to the Ernst1 AudioClip variable in the Inspector. Then you should attach an AudioSource component to the gameobject, declare an AudioSource typed variable (lets name it 'audioManager'), and assign the AudioSource to the variable with this line:
audioManager = GetComponent<AudioSource>();
Whenever you want to play the sound, you can use:
audioManager.PlayOneShot(Ernst1);
there is something wrong with the audio$$anonymous$$anager = GetComponent(); part. its says : Unexpected token: ). and expecting ), found ';'. and ';' expected. Insert a semicolon at the end.