- Home /
Can't figure out how to use multiple triggers in single scene
I have a simple ball bouncing game where I would like a ball to make contact with multiple different triggers. One trigger causes the ball to slow down, another causes a lose state that repeats the level. The problem I am having is that I can't figure out how to differentiate the triggers from one another.
I have the OnTriggerEnter attached to the ball but don't know how to tell it which trigger it has entered. Right now I am limited to having only one trigger in the scene because of this.
//Fail Condition Takes you to fail screen and plays particle explosion
var Ball_Explodes : GameObject;
var Explosion_01 : AudioClip;
function OnTriggerEnter (Ball_01 : Collider) {
rigidbody.velocity = Vector3(0,0,0); //Stops ball movement
Instantiate(Ball_Explodes, transform.position, Quaternion.Euler(-90, 0, 0)); //Particle explosion
audio.PlayOneShot(Explosion_01, 0.7); //Plays explosion
NextLevel(); //Runs next level function
]
Answer by Chronos-L · Apr 07, 2013 at 08:34 AM
Make this modifications to your script,
function OnTriggerEnter (triggerType: Collider) {
if( triggerType.CompareTag( "Fast" ) ) {
}
else if( triggerType.CompareTag( "Slow" ) ) {
}
else ...
}
You then tag the triggers with different tag. When the ball with this script enter the trigger area, it will check for the trigger's tag and ran the corresponding codes.