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 PaxStyle · Feb 11, 2014 at 07:58 PM · audiovelocity

Audio Velocity

Hi! How can I increase the audio velocity, when i press a key? Any help is good! :)

Thank you

Comment
Add comment · Show 2
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 iamvishnusankar · Feb 11, 2014 at 08:06 PM 0
Share

Are you asking about increasing/decreasing the speed of audio play?

avatar image PaxStyle · Feb 11, 2014 at 09:03 PM 0
Share

Yes. but increasing the reproduction speed audio, non the volume sorry.

1 Reply

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

Answer by iamvishnusankar · Feb 11, 2014 at 09:15 PM

If you're talking about Audio pitch. Try this code

 public float _audioSpeed = 1.2f;
 
 void Start()
 {
   audio.pitch = _audioSpeed;
 }
 

You could change it from inspector also.

or Use a horizontal ScrollBar to change the pitch

 public float hSliderValue = 0.0;
     
 function OnGUI () 
 {
 
 hSliderValue = GUI.HorizontalSlider (Rect (25, 25, 100, 30), hSliderValue, -3.0f, 3.0f);
 
 audio.pitch = hSliderValue ;
 
 }
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 PaxStyle · Feb 12, 2014 at 03:06 PM 0
Share

Ok, I tried so, I put the AudioClip, but how call it in the script? and in this script, when I press a key, the audio playback speed increases? I would like this.. sorry for my english. ;)

 using UnityEngine;
 using System.Collections;
 
 public class Audio : $$anonymous$$onoBehaviour {
     public float aspeed = 1.2f;
     public AudioClip $$anonymous$$otore;
 
 
     // Use this for initialization
     void Start () 
     {
       audio.pitch = aspeed;
     
     }
     
     // Update is called once per frame
     void Update () 
     {
         if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.Z)) 
         {
             aspeed += 1;
         }
         if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.X)) 
         {
             aspeed -= 1;    
         }
     }
 }
 
avatar image iamvishnusankar · Feb 12, 2014 at 03:39 PM 1
Share

Try rewriting your script as follows. I hope this will solve your problem.

 using UnityEngine;
 using System.Collections;
  
 public class Audio : $$anonymous$$onoBehaviour
  {
     public AudioClip $$anonymous$$otore;
 
     void Start()
    {
     audio.clip = $$anonymous$$otore;
    }
  
  
     // Update is called once per frame
     void Update () 
     {
        if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.Z)) 
        {
         audio.pitch +=0.2f;
        }
        if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.X)) 
        {
          audio.pitch -=0.2f;
        }
     }
 }
avatar image PaxStyle · Feb 12, 2014 at 04:00 PM 0
Share

hmhmh ok it work! two more questions: 1) how can I set the pitch max-limit at 3 and the $$anonymous$$imum at 0?

2) i added the audio source in unity editor with the current audio, but if i don't click on "play awake" the audio dosn't start, but i would like that it starts when I press a key.
How can i put in the script the auto-play at 0.0?

thank you, paolo

avatar image iamvishnusankar · Feb 12, 2014 at 04:25 PM 0
Share
  1. Add this code on Update() fucntion

    //Clamp audio pitch between 0 & 3

    $$anonymous$$athf.Clamp(audio.pitch,0f,3f)

  2. Add this code on Start() to play audio without clicking awake

    void Start()

    {

    if (!audio.playOnAwake) audio.Play();

    }

For further info refer Unity documentation about AudioSoure

Leave an acceptance if this solve your problem. Cheers. :)

avatar image PaxStyle · Feb 12, 2014 at 04:55 PM 0
Share

ok the firts one work, but the second no.. why? :P I put it here:

 void Update () 
     {
         $$anonymous$$athf.Clamp (audio.pitch, 0f, 3f);
 
         if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.Z)) 
         {
             audio.pitch +=0.2f;
         }
         if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.X)) 
         {
             audio.pitch -=0.2f;
         }
     }

i don't know where i can find my solution problem in script reference.. :/

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

19 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

Related Questions

play sound when player reaches a certain speed 1 Answer

How can I use Unity's Doppler effect with high velocity objects? 1 Answer

How I can change the speed of an object with the speed of sound so they are evenly matched? 2 Answers

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

Audio Problem with multiple audio Sources 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