I have looked through all the forum but still do not have an answer… HOW can we trigger to play audio clip when our main camera collides with another object?
Please help! I’m a noob programmer…
I have looked through all the forum but still do not have an answer… HOW can we trigger to play audio clip when our main camera collides with another object?
Please help! I’m a noob programmer…
Most the basics can be learned in the demo tutorials free to download here at the site. Most users here love to help others out. You can learn alot from the tutorials += the Scripting manual where there are many examples like this one. ![]()
If you have any kind of collider child or parent to your camera you can use
OnTriggerEnter or OnCollisionEnter ect to check for collision.
var aSound : AudioClip;
function OnCollisionEnter(collision:Collision){
//Here we check the items name we collide with.
if(collision.gameObject.tag=="TagName"){
audio.PlayOneShot(aSound);
}
}
If you dont care about what objects hit the camera and set off the sound then just take the if statment out.
++ Trigger (ie)
var aSound : AudioClip;
function OnTriggerEnter(col : Collider) {
audio.PlayOneShot(aSound);
}
It should be as simple as this although i did’nt test this code its just from memory. ![]()
SOLVE. Thank you very much.
I made a java script with the code as follows:
var aSound : AudioClip;
function OnCollisionEnter(collision:Collision){
//Here we check the items name we collide with.
if(collision.gameObject.tag==“TagName”){
audio.PlayOneShot(aSound);
}
}
and it just gave me compiler errors. Am I doing something wrong? Is there something I have to add to that script? I’m really new at this and would appreciate any help.