- Home /
Two questions to long for title
ok i know the title is stupied but its true my questions are to long.
can I make it so if my enemy is in a certin range it plays certine whipering (creepy) sounds
can I also make it so if my flashlight (spotlight) shines on my enemy it disapers and stops the sound or makes it louder 3.thanks in advance if you can help people
Answer by cdrandin · Jan 17, 2013 at 05:03 AM
Yes and yes. Quite simple thanks to Unity.
This will just be pseudocode, but it should work
1) Assume target as a Transform type. This script is attached to the player. if Vector3.Distance(transform.position, target.position) < 20 //assume 20 meters within range then Play creepy sound. Place sound on target. Send a message and have the target contain a function which receives a signal when to play this sound.
2) Use a spotlight and modify it to your liking then put it in front of this flashlight object. Then create a RayCast pointing out of the flashlight point to check for collision and if the collision hits this "monster" tag, meaning our target, then have the script call the target's play sound function and increase the sound or w/e. You can make the functions unique by passing in parameter for how loud or change in frequency. For this look up RayCast and HitRayCast in the Unity docs.
thanks very much im a nood with scripting could you give me a link to any examples, like in the unity wiki or something like that??? thanks again