I need to activate a sound clip when my first person controller drops an object with a box collider and rigid body onto another object with a box collider. any suggestions as to how i would achieve this?
There are these two things you want:
The condition being: A collision between 2 box colliders
The reaction being : Play a sound file
These are actually 2 questions, do you have trouble with playing sound or detecting collisions or both?
Here's some suggestions that assume the worst case scenario:
Triggers
An alternative way of using Colliders
is to mark them as a Trigger, just
check the IsTrigger property checkbox
in the Inspector. Triggers are
effectively ignored by the physics
engine, and have a unique set of three
trigger messages that are sent out
when a collision with a Trigger
occurs. Triggers are useful for
triggering other events in your game,
like cutscenes, automatic door
opening, displaying tutorial messages,
etc. Use your imagination!
Your collision response could come from a trigger by objects carrying tag properties
Another idea may be to have the rigidbody of each object check for collisions (which the physics engine does ) catch the message using the suggestion spree just handed you and when you caugth the collision message you can use the same reaction you would in situation 1.
To play an audio file you will need to attach it to the object probably, and since collisions between different objects cause different sounds both objects should play the sounds maybe, up to you I guess what you want to hear.
To play sound, load the sound into a public variable with the type AudioSource
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour
{
public AudioSource myCampFireSoundThingy;
public void someEvent()
{
myCampFireSoundThingy.Play();
}
}
use OnCollisionEnter. You could attach an audiosource with the correct audioclip to your object and then OnCollisionEnter do audio.Play();