The good news is: Yes, this can all be achieved.
The bad news is: It takes more than a single script to pull it off.
And the ugly news is, that "enemies that randomly pop up" are amongst the biggest risks in level design as they can damage the game flow, imbalance the difficulty and create illogical spawning.
Here is my method for spicing up gameplay a little:
1.
I set up a corridor with a dynamic door which the player has to pass by, ideally it is at a point in the level where the player has to pass by the door several times.
2.
The door cannot be opened by the player and is scripted to make a random 50% check each time the player passes by. On the "right" outcome the door automatically opens.
3.
Behind the door an enemy is placed with a script that makes him attack as soon as he sees the player. Once the door script opens it, the enemy attacks.
4.
To have the enemy play some "dramatic music", his script has to be altered, so that as long as PLRCANBESEEN is true and the enemy is not destroyed the music plays, otherwise it stops. The hook is, that this might hamper the enemy playing his usual soundset.
I know this setup is not very flashy but it's logical (the enemy opened the door himself), random enough to surprise the player but still easy to balance with the rest of the level.
Coincidencely I am working on a "scary door" script atm, that makes the door play random banging sounds, and if it would help you, I'll do antoher version for opening the door. This script would then kind of warn the player that there IS something behind the door without actually opening it until the player doesnt think of it dangerous anymore
In case you find my grammar and spelling weird ---> native German speaker ^^