- Home /
OnTriggerEnter problem
var source : GameObject; var source1 : GameObject; var cube1 : Transform; var cube2 : Transform;
function Start() { source.active = true; source1.active = true; }
function OnTriggerEnter (other : Collider) {
//var cube5 : Collider; if(other.gameObject.name == "cube1") { source.audio.Play(); source1.audio.Stop(); Debug.Log("FIRST"); }
if(other.gameObject.name == "cube2") { source1.audio.Play(); source.audio.Stop(); Debug.Log("SECOND"); }
}
There is FIRST person camera and two boxs cube1 and cube2 when the boxs enter the first person camera respective AUDIO should play and also a print statement according to the box my problem is when box enter the FPC nothing is happening source and source1 is audio clips attached to game object any help
Answer by owenpat · Mar 04, 2011 at 07:17 AM
Take a look at OnBecameVisible
instead of using a triggerbox.
OnTriggerEnter runs when something hits you. The way you have it, the objects need to actually ram the camera in order to do anything (but not even then, since cameras don't have colliders.) If you gave the camera a BoxCollider and stretched that out way in front of it, that would almost work, if the cubes walked into the camera. The problem is that triggerBoxes don't trigger when you move them into something -- only when something moves into them.
Answer by Steffen Franz · Jan 31, 2011 at 08:38 PM
two things I can see:
a) try if(other.CompareTag("Cube1"))
.
b) Also your source should be an AudioSource, not a GameObject (or at least you need to link the AudioSource on that GameObject to play the Audio).
and just to confirm, you do have a Collider on each of the boxes.
Answer by 3DMagicVR · Jan 31, 2011 at 08:40 PM
Hi, you must use the:
var someAudio : AudioClip; // or
var someAudio : AudioClip[]; // to use multiple sounds
audio.clip = someAudio;
to make the sound could be played, and make sure you are activatening the Is Trigger on the collider component to make the object a trigger, one thing, the script must be on the objet that will make contact with the trigger.
Your answer
Follow this Question
Related Questions
OnTriggerExit() help 0 Answers
on trigger enter 1 Answer
i need detailed instructions... cue texture 1 Answer
fetching a value 1 Answer
On trigger enter play sound problem 2 Answers