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 zmar0519 · Apr 28, 2011 at 08:10 PM · guiaudiopitchrewindfastforward

Rewind button works but not fast forward button?

Hello, everyone. I'm doing a project for school on the connection of music to the brian, and I'm using Unity because of it's gui system. I need to be able to fast forward and rewind audio clips, and I'm doing so with audio.pitch. However, the fast forward button has no effect, but the rewind button works fine. All help would be appreciated!!! :)

Here is my code:

@script RequireComponent(AudioSource)

private var INFOscrollVector : Vector2 = Vector2.zero; private var AUDIOscrollVector : Vector2 = Vector2.zero;

var info : String; var songs : AudioClip[]; var clipButtonSize : float; var PlayIcon : Texture2D; var PauseIcon : Texture2D; var ffIcon : Texture2D; var rwIcon : Texture2D; var showAudioInterface : boolean = true; private var aClip : AudioClip; private var p : float;

function Awake() { p = audio.pitch; } function OnGUI() { AudioInterface(); } function Update() { audio.clip = aClip; } function AudioInterface() { //Background Boxes GUI.Box(Rect(10, 10, Screen.width/2-5, Screen.height - 60), ""); GUI.Box(Rect(Screen.width/2+5, 10, Screen.width/2-10, Screen.height - 60), ""); GUI.Box(Rect(10, Screen.height-50, Screen.width - 15, 40), ""); //The Play/Pause and other options GUI.BeginGroup(Rect(10, Screen.height-50, Screen.width - 15, 40)); if(GUI.Button(Rect(0, 0, 40, 40), PlayIcon)) { audio.Play(); } if(GUI.Button(Rect(40, 0, 40, 40), PauseIcon)) { audio.Pause(); } if(GUI.RepeatButton(Rect(80, 0, 40, 40), ffIcon)) { audio.pitch = p * 2; } else { audio.pitch = p; } if(GUI.RepeatButton(Rect(120, 0, 40, 40), rwIcon)) { audio.pitch = p/2; } else { audio.pitch = p; } GUI.EndGroup();

 //The Info Scroll View
 INFOscrollVector = GUI.BeginScrollView(Rect(10, 10, Screen.width/2-5, Screen.height - 60), INFOscrollVector, Rect(10, 10, Screen.width/2-25, 10000));

     GUI.Label(Rect(10, 10, Screen.width - 20, 10000), info);

 GUI.EndScrollView();

 //The Audio Scroll View
 AUDIOscrollVector = GUI.BeginScrollView(Rect(Screen.width/2+5, 10, Screen.width/2-10, Screen.height - 60), AUDIOscrollVector, Rect(10, 10, Screen.width/2-30, clipButtonSize*songs.length));
 for(i = 0; i < songs.length; i++)
 {
     if(GUI.Button(Rect(10, 10+(i*clipButtonSize), Screen.width/2-30, clipButtonSize), songs[i].name))
     {
         aClip = songs[i];
     }
 }

 GUI.EndScrollView();

}

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
Best Answer

Answer by Richard J. Hansen · Apr 29, 2011 at 02:06 AM

I don't have any experience with playing around with pitch, but I think your problem is here.

if(GUI.RepeatButton(Rect(80, 0, 40, 40), ffIcon))
    {
        audio.pitch = p * 2;
    } else
    {
        audio.pitch = p;
    }
    if(GUI.RepeatButton(Rect(120, 0, 40, 40), rwIcon))
    {
        audio.pitch = p/2;
    } else
    {
        audio.pitch = p;
    }

After you set the pitch faster for the ff button you then check the rewind button. However, since you aren't pressing the rewind button, it sets the pitch back to 'p.'

Something like this would be better.

audio.pitch = p;
if(GUI.RepeatButton(Rect(80, 0, 40, 40), ffIcon))
    {
        audio.pitch = p * 2;
    }
    if(GUI.RepeatButton(Rect(120, 0, 40, 40), rwIcon))
    {
        audio.pitch = p/2;
    }

NOTE: in my preview window it does not look like the code tags are going to work for this post: not sure why. If it does come out ugly, I will come back to it and edit it with a different browser later.

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

Fast forward an audio clip 1 Answer

Animate Audio Source Pitch/Speed in Timeline 0 Answers

Is it possible to raise an audio sources pitch as an audio listener gets closer? 5 Answers

Checking collision between 2 triggers based on distance. Possible? 1 Answer

How do I get the fundamental frequency pitch for audio input? 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