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 bill18ization · Jul 23, 2014 at 06:25 AM · audiotriggeraudioclipaudioplay

How to create an audio manager script with input from triggers?

I have got five triggers in my scene.

On entering each trigger I would like to play a particular music. When a new audio starts playing I want the previous one to be stopped.

I want to create one script for controlling all the audio so that it reduces the memory usage.

I am not able to understand how I can get access to the various variables required for this.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sethuraj · Jul 23, 2014 at 11:00 AM

Before getting into the solution,try to convert your logic to code and at least try to show your progress in code so that we can help you. Ok for now you can implement something like this.Create a soundmanager script which will hold all sound datas and to which you will make calls to play each sound

This is the sound manager script "SoundManager.cs" use it on an empty gameObject

 //The AudioSource to which we play any clips
 private AudioSource A_Source;
 
 //The audioclips which you should assign through inspector
 public AudioClip Clip_00;
 public AudioClip Clip_01;
 public AudioClip Clip_02;
 public AudioClip Clip_03;
 public AudioClip Clip_04;
 
 //Singleton accessor
 public static SoundManager Instance;
 
 void Awake()
 {Instance=this;}
 
 void Start()
 {
   //Add the audio source
   A_Source= gameObject.AddComponent<AudioSource>();
 }
 
 public void PlaySoundTrack(int TrackID)
 {
 
   //Stop any playing music
   A_Source.Stop();
 
   switch(TrackID)
   {
     case 1:
     A_Source.PlayOneShot(Clip_01);
     break;
 
     case 2:
     A_Source.PlayOneShot(Clip_02);
     break;
 
     case 3:
     A_Source.PlayOneShot(Clip_03);
     break;
 
     case 4:
     A_Source.PlayOneShot(Clip_04);
     break;
 
     default:
     A_Source.PlayOneShot(Clip_00);
     break;
   }
 
 }



In your five trigger script's OnTriggerEnter functions use like this

 public int ID_Collider=0;
 
 void OnTriggerEnter(Collider Target)
 {
   if(Target.gameObject.Tag=="Player")
   {
     //Since the sound manager class name is SoundManager.cs
     SoundManager.Instance.PlaySoundTrack(ID_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
avatar image
0

Answer by dinuraimesh · Jan 30, 2019 at 03:50 AM

The post is old. But guess this would be helpful for everyone. This audio manager gives control over every every audio clip with effects.

Audio Manager for 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Problem with playing sound on Trigger-Enter 2 Answers

Playing audio brings this error: An invalid seek position was passed to this function. Does anyone knows what does this mean? 1 Answer

One sound gets quieter when other is played? 1 Answer

play audio from frequency and amplitude file 0 Answers

Getting audio to play on collision 3 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