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 fernandovt · Sep 28, 2013 at 07:01 AM · soundontriggerentermouseclickdoor

Door Sound Script Help

Hey I have some issues with the sound script for my door, so my door has a box collider with a trigger and it gets open with a mouse click. But i have this separate script for the door sound, and i guess it misses the ontriggerenter or something because it doesnt matter where I'm in the map, when I click, the door sound gets activated. I know it's probably easy to fix, but I'm not too good yet in scripting. So what i want is that the sound gets activated only if the player clicked on the trigger of the door (inside the box collider); Here is the sound script:

var shootSound:AudioClip;

function Update () { if(Input.GetKeyDown(KeyCode.Mouse0)){ audio.PlayOneShot(shootSound); } }

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Visual Programmer · Sep 28, 2013 at 08:20 AM

I get what you're trying to do. Use OnMouseDown(); it's great for non-mobile point and click games.

 function OnMouseDown(){
     audio.PlayOneShot(shootSound);
 }
 


Comment
Add comment · Show 2 · 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 fernandovt · Sep 29, 2013 at 07:52 PM 0
Share

I want that the sound plays when I click inside the box collider of my door(wich is a trigger), because my current script make the door sound play everywhere i click in my map, and I need it to play only when i'm inside the box collider of my door, something like this but that works, because i don't know why this doesn't:

pragma strict

var shootSound:AudioClip;

function OnTriggerEnter (other : Collider) { if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$ouse0)){ audio.PlayOneShot(shootSound); } }

Do you have any suggestions?, I'm really looking forward this script, it will work when i click over different objects making different sounds (windows, drawers, buttons, etc)

avatar image Visual Programmer · Sep 29, 2013 at 10:20 PM 0
Share

Bump Updated answer

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

17 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

Related Questions

Door Opens When Not In Trigger And Sound Help 1 Answer

Animate Doors and Button Through Script 1 Answer

How would I play a sound in a certain range of an object? 1 Answer

Open door without using tag 1 Answer

Door open/load level java script troubles 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