Hello people
i have 3 soundeffects. if an object hits an other object it must play 1 of the 3 sounds randomly.
thanks


1 2 3 4 5 6 7 8 9 10 11 12 | if ( object != null ) { int rand = Greenfoot.getRandomNumber( 2 ); if (rand == 0 ) { Greenfoot.playSound( "gered.wav" ); } else if (rand == 1 ) { Greenfoot.playSound( "gered1.wav" ); } } |
1 2 3 4 5 6 7 8 9 10 11 | if (object != null ) { if (Greenfoot.getRandomNumber( 2 ) == 0 ) { Greenfoot.playSound( "gered.wav" ); } else { Greenfoot.playSound( "gered1.wav" ); } } |
1 2 3 4 5 6 7 8 9 | if (obect != null ) { switch (Greenfoot.getRandomNumber( 3 )) { case 0 : Greenfoot.playSound( "gered.wav" ); break ; case 1 : Greenfoot.playSound( "gered1.wav" ); break ; case 2 : Greenfoot.playSound( "gered2.wav" ); break ; } } |