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 /
  • Help Room /
avatar image
0
Question by El__Nacho · May 17, 2016 at 09:43 PM · c#androidaudiotransitionvolume

Code works in editor, but not on Android device(audio mixer)

Hey have created a script which should make a transition between two audio mixer groups and it works fine if I test it in the editor: the first groups volume decreases and the other groups volume increases. After the transition the volumes don't change in the editor, but if I run my game on my HTC One M9 the transition works and after it the first groups volume jumps to 100% although it should be 0.

The Coroutine which makes the transition is the changeChannel IEnumerator at the bottom of the script.

If you need an example you can download https://www.dropbox.com/s/riwis1zj4utjb9l/Android%20sound%20test.zip?dl=0, this is an example project using the code below.

Do you know why it doesn't work?

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Audio;
 
 public class AudioScr : MonoBehaviour {
     public AudioMixer masterMixer;
     public float changeMusicChannelTime;
     private float lastPitch=0, currentPitch,currentTime,progress;
     // Use this for initialization
     void Start () {
         masterMixer.SetFloat ("MmusicVol", 0);
         masterMixer.SetFloat ("IGmusicVol", -50);
     }
     
     // Update is called once per frame
     void Update () {
         currentPitch = Time.timeScale;
         if (currentPitch != lastPitch) {
             masterMixer.SetFloat ("IngameMusicPitch", currentPitch);
         }
         if (currentPitch == 0 && lastPitch != 0) {
             
             StartCoroutine (changeChannel (false));
         } else if (currentPitch != 0 && lastPitch == 0) {
             
             StartCoroutine (changeChannel (true));
         }
         lastPitch = currentPitch;
     }
 
     public void changeChannelTimeAdjust(float newTime){
         changeMusicChannelTime = newTime * 5+0.1f;
     }
 
     public void SetEffectVolume(float effectVol){
         if (effectVol != 0) {
             effectVol = 20 * Mathf.Log10 (effectVol);
         } else {
             effectVol = -50;
         }
         masterMixer.SetFloat ("effectVolume", effectVol);
     }
 
     public void SetMusicVolume(float musicVol){
         if (musicVol != 0) {
             musicVol = 20 * Mathf.Log10 (musicVol);
         } else {
             musicVol = -50;
         }
 
         
         masterMixer.SetFloat ("musicVolume", musicVol);
     }
 
     IEnumerator changeChannel(bool purpose){
         Debug.Log ("Start channel switch: "+purpose);
         do{
             currentTime += Time.unscaledDeltaTime;
 
             progress = currentTime / changeMusicChannelTime;
 
             if (purpose) {
                 //from Menue to Ingame
                 float MmusicVol = 20 * Mathf.Log10 (1-progress);
                 float IGmusicVol = 20 * Mathf.Log10 (progress);
                 if (progress == 0) {
                     IGmusicVol = -50;
                 } else if (progress == 1) {
                     MmusicVol = -50;
                 }
 
                 masterMixer.SetFloat ("MmusicVol", MmusicVol);
                 masterMixer.SetFloat ("IGmusicVol", IGmusicVol);
             } else {
                 //from Ingame to Menue
                 float MmusicVol = 20 * Mathf.Log10 (progress);
                 float IGmusicVol = 20 * Mathf.Log10 (1 - progress);
                 if (progress == 0) {
                     MmusicVol = -50;
                 }else if (progress == 1) {
                     IGmusicVol = -50;
                 }
 
                 masterMixer.SetFloat ("MmusicVol", MmusicVol);
                 masterMixer.SetFloat ("IGmusicVol", IGmusicVol);
             }
             yield return null;
         }while (progress < 1);
         progress = 0;
         currentTime = 0;
 
 
     }
             
 
 
 
 }

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 El__Nacho · May 18, 2016 at 06:04 PM

Oh I found a solution :D In line 68 and 80 I was using the progress==1 condition, so if the value wasn't exactly 1 the code wouldn't work. The volume dropped below -80dB and the editor has handled it for some reason but my phone hasn't and reseted it to 0dB. Now I have replaced it by progress>=1 and it works.

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

169 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 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 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 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 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 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 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 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

Adroid Changing the game volume 1 Answer

Unity custom Audio Manager won't work with custom Stop function 1 Answer

How Do I Make A Change A Volume With A Slider? 3 Answers

[App Android/Ios/Windows Phone] phone's volume 0 Answers

Code is not executed after build to android. 0 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