Search Unity

[Solved] Changing the pitch of AudioMixer by code

Discussion in 'Audio & Video' started by probitaille, Jun 9, 2015.

  1. probitaille

    probitaille

    Joined:
    May 5, 2015
    Posts:
    34
    Hi,

    Can we change the pitch of an AudioMixer by code (C#)? We can from the inspector.
    It's seems like the AudioMixer object don't have any method for this.

    Thank you.
     

    Attached Files:

    Bakanovskiy95 and Panickal like this.
  2. aihodge

    aihodge

    Joined:
    Nov 23, 2014
    Posts:
    163
    You have to expose the Pitch parameter to script control. Right click on the parameter name "Pitch" and choose "Expose 'Pitch' to script". Give it a name in the Exposed Parameters drop down on the AudioMixer view in the editor. Then you can use mixer.SetFloat("myParameterName", 0.5f); to change the value from one of your scripts.
     
  3. probitaille

    probitaille

    Joined:
    May 5, 2015
    Posts:
    34
    Thank you for your response!

    If someone is looking where the dropdown is, here is a picture that shows.
     

    Attached Files:

  4. Rob-Meade

    Rob-Meade

    Joined:
    Oct 27, 2016
    Posts:
    56
    Thank you both for the information relating to finding the exposed parameters - that was quite a search! :)
     
    Bakanovskiy95 and aihodge like this.
  5. Luccathegreat

    Luccathegreat

    Joined:
    Apr 30, 2022
    Posts:
    26
    Is this not what I should do?
    upload_2022-5-24_8-20-25.png
    exposer param:
    upload_2022-5-24_8-20-38.png

    I get this error on the ".5f":
    upload_2022-5-24_8-21-33.png
     

    Attached Files:

    Bakanovskiy95 likes this.
  6. aihodge

    aihodge

    Joined:
    Nov 23, 2014
    Posts:
    163
    You just need to declare a float variable to put the retrieved value into:

    Code (CSharp):
    1. float myPitchValue;
    2.  
    3. audioMixer.GetFloat("pitch", out myPitchValue);
    4.  
    5. print("myPitchValue: " + myPitchValue.ToString());
     
    Bakanovskiy95 likes this.