- Home /
When dragging a Door open using RIGIDBODYSCRIPT Plays sound.
Using the DragRigidBody script from the Dynamic Shadows Demo. Doors open/close perfectly fine. Curious how i could make it so when the player clicks and drags to open a door it plays a sound?
Answer by Dark_Moo · Oct 02, 2012 at 10:44 PM
Hello, you can have an event happen when the player clicks on the door with
Javascript:
function OnMouseDown () {
//Audio Code Here
}
C#:
void OnMouseDown() {
//Audio Code Here
}
Hope this helps.
Yeah but that just plays audio when clicking down on the mouse. I'm trying to get it so when I'm activley dragging the door open via the rigidbodyscript it plays a sound. I stop dragging the sound stops. I click and start dragging open the door it starts playing sound again.
kk, what if you set the door to sleep by default, and On$$anonymous$$ouseDown you wake it up and if the door is awake you can use:
if (!rigidbody.IsSleeping())
{
//Play Sound
}
and you can use On$$anonymous$$ouseUp to make the door sleep again
so it would look something like: C# code:
void On$$anonymous$$ouseDown()
{
rigidbody.WakeUp();
}
void On$$anonymous$$ouseUp()
{
rigidbody.Sleep();
}
void Update()
{
if (!rigidbody.IsSleeping())
{
//Play Sound
}
}
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
how to create Magnetic repulsion ? 0 Answers
Faux Gravity Prolem? #2 2 Answers
Hooking RigidBody.AddForce 0 Answers
Finding the axis of a curving pipe 0 Answers