Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Trevor 1 · Feb 27, 2010 at 01:08 AM · animationphysicsaudioaudiosource

What is the script code on how to trigger a song for the player to Listen to?

What is the code for the player to collide with and trigger a music source to the player to hear as an Audio Source not at the current position. Because I am having difficulty making the player collide with the trigger and everything would work but there would be no direct sound for the player to listen to. SO if you could help I would really appreaciate it. ALOT!

Comment
Add comment · Show 3
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 JDonavan 1 · Feb 27, 2010 at 01:33 AM 0
Share

By "not at the current position" do you mean you want to trigger a sound somewhere else in the scene?

avatar image Jason_DB · Feb 27, 2010 at 02:55 AM 0
Share

Just a note: you don't need to post your question again if it isn't immediately answered, its still on the site so reposting it just kind of clutters.

avatar image Trevor 1 · Feb 27, 2010 at 03:17 AM 0
Share

Yes to where you first start off by not hearing any music play untill you reach a certain point of the level $$anonymous$$usic would start to play like if it were HALO or somethin.

2 Replies

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

Answer by xToxicInferno · Feb 28, 2010 at 04:13 AM

I am not sure if this is what you wanted but here is what i got out of it, I decided to add comments to make things easier for you.

// This is a public variable so you have to assign the audio clip you wish to play in the Inspector var HaloTheme : AudioClip;

 // Make a box, delete the mesh renderer, and make the Box Collider a trigger by selecting 'Is Trigger'
 // Then expand it to enclose the whole area you wish it to cover, ie a room.
 function OnTriggerEnter (other : Collider) {
 // Make sure your character is tagged 'player'
 if (other.gameObject.tag == "player") {

 // Plays the audio that you want...
         audio.Play(HaloTheme);
     }
 }

 // Simply makes it so the object can play audio
 @script RequireComponent(AudioSource) 

Also, i didn't put a comment in there for it, but on the Audio Source comopnet that is added, make sure you have it set to Loop, if you want it to loop that is.

Lastly, take a look at this for other Audio related scripting issues: Unity Scripting Reference: Audio Source

Hopefully i have helped out, good luck and have fun with Unity!!

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 StephanK · Feb 27, 2010 at 11:47 AM

Not sure if I understand your question, but if you want to start a jukebox when a player is entering the room the only thing you have to do is attach a trigger collider to the jukebox that contains the room or area where the music should be heard. Then OnTriggerEnter start the AudioSource. If the clip attached to the AudioSource is marked as a 3d sound the music's level will depend on the distance of the AudioListener (probably attached to your cam/player) to the AudioSource. If you don't want that disable the clip's 3d sound property.

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

No one has followed this question yet.

Related Questions

GameObject reacts to audio source 1 Answer

Audio Source Pitch effect Legacy Animation 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

FixedUpdate after Animation - Physics Loop 5 Answers

Door script not completely working help! 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