i have a bunch of colored balls rolling around and theres a bunch of colored boxes, i want the red ball to make the red box go flying if they touch but if another color touches it it just acts like a normal rigid body
how do i tell the box to go flying when a specific ball hits it??
What about what triggered what- This is a box that should open only when the Player is near it:
Thanks IA
var Player:GameObject;
var hingeOpen:GameObject;
var hingeClose:GameObject;
function OnTriggerEnter (Player: Collider) {
Debug.Log("Open");
animation.Play("open");
hingeOpen.audio.Play();
}
function OnTriggerExit(Player: Collider) {
Debug.Log("Close");
animation.Play("close");
hingeClose.audio.Play();
}
These changes, in addition to making sure the player has the tag “Player”, should work. I took the liberty of changing your audio sources to the correct type, so you can refer to variable.Play() rather than variable.audio.Play().
var hingeOpen:AudioSource;
var hingeClose:AudioSource;
function OnTriggerEnter (other : Collider) {
if (other.tag == "Player") {
Debug.Log("Open");
animation.Play("open");
hingeOpen.Play();
}
}
function OnTriggerExit(other : Collider) {
if (other.tag == "Player") {
Debug.Log("Close");
animation.Play("close");
hingeClose.Play();
}
}
To make this code even more intuitive, you might want to attach an AudioSource to the chest, and then have your two sounds be referenced clips. This way, you only need one AudioSource, and so you don’t have to make separate objects for your open and close noises.
var hingeOpen : AudioClip;
var hingeClose : AudioClip;
function OnTriggerEnter (other : Collider) {
if (other.tag == "Player") {
Debug.Log("Open");
animation.Play("open");
audio.PlayOneShot(hingeOpen);
}
}
function OnTriggerExit(other : Collider) {
if (other.tag == "Player") {
Debug.Log("Close");
animation.Play("close");
audio.PlayOneShot(hingeClose);
}
}