Forum Discussion
saviornt
12 years agoProtege
Audio Source Array attached to camera
Good morning, after a long night of research, I have come to the community for guidance / help on this :(
The idea is pretty straight forward, attach multiple audio sources to the player's camera, so that when the player runs into a trigger source, I can control where the sound comes from in relation to where the player is looking. However, not only does the sound not play, I'm not even getting a trigger event in my Debug.Log :evil:
Here is the code that I am using on the trigger:
I select the sound, selected the audio source, and made sure that the box collider was set to isTrigger. It seems pretty straight forward, but I'm not having any luck :\
Any ideas? I'd be a happy panda if I could figure this out, lol
The idea is pretty straight forward, attach multiple audio sources to the player's camera, so that when the player runs into a trigger source, I can control where the sound comes from in relation to where the player is looking. However, not only does the sound not play, I'm not even getting a trigger event in my Debug.Log :evil:
Here is the code that I am using on the trigger:
#pragma strict
var audioFXClip : AudioClip;
var playOn : AudioSource;
private var hasPlayed = false;
function onTriggerEnter(){
Debug.Log("Player has entered the trigger area");
if (!hasPlayed){
playOn.PlayOneShot(audioFXClip);
Debug.Log("The audio has triggered");
hasPlayed = true;
}
}
I select the sound, selected the audio source, and made sure that the box collider was set to isTrigger. It seems pretty straight forward, but I'm not having any luck :\
Any ideas? I'd be a happy panda if I could figure this out, lol
4 Replies
Replies have been turned off for this discussion
- virrorExplorerMake sure both the area and the player has a collider attached and also make sure one of them has a rigidbody, or it wont work.
- ArowxExplorerI think virror has hopefully hit the nail on the head.
One possible problem with this approach is that you will lose the sound offset effects that you would have if the audiosource is placed at the trigger position. - vajra3dHonored GuestYour problem is here:
" onTriggerEnter" should be "OnTriggerEnter"
Also, if you do something like this then it will print to the console the name of the gameObject that has triggered the collider if indeed it is triggering it at all:function OnTriggerEnter (other : Collider) {
print (other.collider.name);
}
A better option in your case might be to use OnTriggerStay instead.
Also, for something like this I would highly recommend avoiding a standard box collider and instead using a mesh collider with a cube attached to it and then setting it to "convex". This will make sure that the "trigger" collider object stays updated after the player has entered the trigger zone area. Otherwise it will just trigger it once on the initial contact and then switch itself back to the un-triggered state.
Hope that helps and good luck! - saviorntProtegeAnd this is why it is better to have an additional pair of eyes. It was the typo :oops: (OnTriggerEnter rather than onTriggerEnter; wtb a programming language that does what I want it to do, not what I tell it to do :lol: )
As far as having the audio sources placed where I do is (not really) unique to this project. The array will be used more for "scare tactics", rather than audio effects. For example, a whisper to the rear left of the camera, and when you look in that direction, nothing is there :shock:
Another use for the array is for voice / narration, and if I want to position the narrator's voice in a certain location for effect.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 8 months ago
- 7 months ago
- 3 years agoAnonymous