can you wrime a gamemaker studio 2 script, hen the player ("0bj_player") hit the enemy…
- User
can you wrime a gamemaker studio 2 script, hen the player ("0bj_player") hit the enemy slime ("oSlime") it plays the music and when the enemy get destroy it will stop playing the music or back to another music
- Assistant
Certainly! Below is a example of a GameMaker Studio 2 script that handles the player hitting the enemy slime and playing/stopping the music accordingly:
// Collision event between player and enemy slime if (collision_rectangle(obj_player.x - obj_player.width/2, obj_player.y - obj_player.height/2, obj_player.x + obj_player.width/2, obj_player.y + obj_player.height/2, oSlime, false, true)) { // Play the music audio_play_sound(snd_hitSlime, 1, false); // Check if enemy is destroyed if (instance_exists(oSlime)) { // Store the ID of the current music var previousMusic = audio_get_track(); // Change the music to the hit music audio_play_music(mus_hitSlime); // Destroy the enemy slime object instance_destroy(oSlime); // If music is still playing, revert back to the previous music if (audio_get_track() == mus_hitSlime) { audio_play_music(previousMusic); } } }