I have made this code here to play a little tune when my character dies, and I have come to a road block. before you look at my code, you must know that I assigned all the variables through the editor, and also that it is written in JavaScript.
Here it is:
#pragma strict
var CharacterPosition : Transform;
var DeathSound : AudioSource;
var DeathRespawnPoint : Transform;
var DeathPoint : int = -15;
var AlreadyStarted : boolean = false;
function FixedUpdate () {
if(CharacterPosition.position.y == DeathPoint && AlreadyStarted == false){
AlreadyStarted = true;
DeathSound.Play();
if(DeathSound.isPlaying == false){
CharacterPosition.position = DeathRespawnPoint.position;
AlreadyStarted = false;
}
}
}
One last thing you might need to know, is that I used Debug.Log() to try to figure out what wasn’t working in the code, and found that the code that wasn’t running was:
if(DeathSound.isPlaying == false){
CharacterPosition.position = DeathRespawnPoint.position;
AlreadyStarted = false;
}
It seemed as if the code could not tell that the AudioSource had ended, but I did yet another test, and the editor was showing that it did, though the script was not reading it. It has really confused me.
Let me know if there is any other information you need to know to solve my conundrum, and thanks in advance.
P.S.If anyone knows a better way to make a falling death script that would allow music to be played before respawning.