Beginner has a problem with sequence ;)

Hi everybody :slight_smile:

Something’s wrong with my code. I’m trying to make some kind of sequence by pressing GUI button: First step, is the animation of falling bomb. Then, after 2 sec. from the beginning of those animation, the scene is changing to another (“ExplosionTest”). And that’s all. Two steps.

Console shows me: “WARNING: Boolean expression will always have the same value.” I’m trying to make this problem for two days but I can’t. Where is mistake? What I have to do to make it work? Any sugestions? Thanks a lot :slight_smile:

var Bomb : GameObject;
var Anim : Animation;
var Expl : boolean;
 
function Start(){
    Anim = Bomb.GetComponent(Animation);
}
 
function OnGUI(){
    
    if(GUI.Button (Rect(1000, 570, 200, 100), "Fire")) {
        Bomb.animation.Play("Fall", PlayMode.StopAll);
    }
}

function CoUpdate(){
	if(Bomb.animation.Play);

yield WaitForSeconds(2);
     {
      Application.LoadLevel("ExplosionTest");
      }
   }

The cause of the warning is the line:
if(Bomb.animation.Play);

The member “Bomb.animation.Play” is a method, and I think in Javascript, by simply existing, it will resolve to true. (Don’t quote me on that, I’m a C# man!)

I assume that you meant to use something more like:
“if(Bomb.animation.isPlaying)” in your “CoUpdate” method.

Play returns if the animation was able to play or not. It does not return if the animation is playing which I’m guessing is how you are meaning for it to be used in your CoUpdate method.
The Animation class has an IsPlaying method for that.

Beyond that, you have some syntax errors in your CoUpdate method around your if statement.

function CoUpdate(){
  if(Bomb.animation.IsPlaying("Fall")){
    yield WaitForSeconds(2);

    Application.LoadLevel("ExplosionTest");
  }
} 

Since you don’t show it anywhere, I’m also unconvinced that you are starting the CoRoutine that is supposed to run CoUpdate.