I’m extremely new to Unity and I don’t really have too much of an idea of coding and scripting and such, but basically I’m making a game and you explore a labyrinth and there is also a creature roaming around. I have done the basics, but I want it so that a song (a jump scare sound) is played when the creature is a.) In the camera’s view and b.) Close to the character, so that the audio clip plays when people properly see the creature.
You have pretty much all you need in the link above as it deals with distance and line of sight
Still you need to make sure that the monster is not behind the wall, so use a linecast that you cast from your player to the monster. Make sure you disable the layers (The link also has a linecast example)
Then if all returns true, you can play your scary music
if(within range && dot product angle less than angle){
if(!Linecast(player, monster)){
play music
}