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
1
Question by sgreco · Nov 16, 2010 at 04:21 AM · soundtagplay

how do I make a sound play when player controller hits a tagged item

lets say I have a door tagged, "door." what is the code to play a sound when controller hits the tag?

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 MC HALO · Nov 16, 2010 at 04:27 AM

Ok you need to make a new script and add the following code:

var DoorSound : AudioClip;

function OnControllerColliderHit (hit : ControllerColliderHit)

{

if(hit.gameObject.tag == "door") {

AudioSource.PlayClipAtPoint(DoorSound,transform.position);

}

that should do it :)

Comment
Add comment · Show 5 · 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 sgreco · Nov 16, 2010 at 04:59 AM 0
Share

awesome! few questions tho. 1) do I add this to the door or the controller? 2) where do I put the name of my audio file? 3) will the sound play from the controller or the door? (I want the sound co$$anonymous$$g from the door so that if the controller moves away from the door the sound gets quieter)

avatar image MC HALO · Nov 19, 2010 at 02:55 AM 0
Share

Ok thats fine, what you have to do is add this script to the player and. Once you create the variable $$anonymous$$y audio clip it will appear on the inspector mode and you look at the script you just attached on the player and you will see it there :) and the sound will be played from the player if you want you can send me your stuff and i will happily solve it for you i will also add comments so that the code will be easier to understand and etc. if you would like me to help send me on my e-mail address

gto_oni-eyes@hotmail.com

i will be looking forward to help you sgreco :)

avatar image MC HALO · Nov 19, 2010 at 02:55 AM 0
Share

oh and yea sorry for the late reply :)

avatar image DuckieMonster · Apr 30, 2011 at 11:35 PM 0
Share

i have done everything in this correctly and my sound wont play when my player collider hits the other collider (fountain in my case) could it be because i already have a looped sound playing from my player camera...?

avatar image MC HALO · May 01, 2011 at 12:03 AM 0
Share

No that should not be a problem :) if you send it to me i can have a look for you and fix it asap i will need the project folder sent to my google account which is :

Hummad.Nazir@gmail.com

please send the full project file not the script alone :)

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

No one has followed this question yet.

Related Questions

Play sound on collision 1 Answer

How do I play a sound after the mouse goes through an object? 3 Answers

make sound work 0 Answers

repeated player collisions 1 Answer

Background Music 2 Answers


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