Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DimitriUK · Jan 11, 2014 at 02:26 PM · collideraudiosounddoors

Can you make this work? (Click Collider = Make Sound)

Hello, first of all thank you for taking a look at this question as it's been really bugging me.. I've spent at least 7 to 8 hours of research and have found nothing.

Basically, all I want is..

When the user clicks the Mouse Down on a Box collider that is around a button. (E.g, Door Button) I want it to play an open sound, but ONLY when the mouse is clicked on that SPECIFIC collider. The furthest I have got is, being able to make the sound by clicking, but clicking anywhere makes the sound. I want it to make the sound only when I click on the COLLIDER.

SIMPLE WAY: User Clicks on Collider >>> Sound of door opening >>> User Clicks on Collider again >> Sound of door closing.

EXAMPLE: User clicks on the Box collider around the button. (THIS SHOULD THEN MAKE A SOUND, AND THEN WHEN CLICKED ON AGAIN, IT SHOULD MAKE A SOUND AGAIN BUT WHEN THE DOOR CLOSES)

I know from my experience of a little bit of scripting that, it's around the lines if MouseClickDown is pressed again on the same object, Play.AudioIsPlaying, or something like that. Haha, you have the permission to laugh at me now as that was probably all wrong, but you know.. alt text

step 1.jpg (68.6 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Doeko · Jan 11, 2014 at 02:34 PM 0
Share

What have you tried yourself?

avatar image Invertex · Jan 11, 2014 at 02:42 PM 1
Share

You want a Book for if the door is open or not.

If(doorOpen){ PlaySoundClose; //reverse the bool status doorOpen = !doorOpen; If(!doorOpen){ PlaySoundOpen; //reverse the bool status doorOpen = !doorOpen;

This would all be in another IF condition that did a ray collision check based on mouse screen position and did an if gameobject.tag == door check, which has been answered on here many times.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by ICHeeryI · Jan 11, 2014 at 02:40 PM

You can use raycast: http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html

  var once = 0;
             function Update() {
         if (Input.GetMouseButtonDown (0)){
     
                 var hit : RaycastHit; //Raycast hit
                 if (!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition),  hit, 10)){
                     if(hit.collider.gameObject.tag == "Button"){ //You need to assign tag to object  
                         if(once==0)once=1;//Door opens
                         if(once==1)once=2;//Door closes
                      }
                 }
     }
 else if (once==2){
 //We opened and closed it reset
 once=0
 }
 }


You can use: http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnMouseDown.html with: http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnTriggerEnter.html

Good luck!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by HappyMoo · Jan 11, 2014 at 02:41 PM

http://lmgtfy.com/?q=unity+click+on+a+collider

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can you fix my code? (Audio for doors) 2 Answers

How do I fix audio loop delay 2 Answers

Wait for sound is played 2 Answers

Game created that Users can add own music? 1 Answer

Sound not working? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges