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 /
avatar image
1
Question by MooseTrap · Apr 10, 2010 at 12:23 PM · javascripttransformaudiopitch

Changing Audio Pitch Dynamically

Hi guys,

I want to have an object that can be manipulated to change the pitch of a sound that is playing as it plays, and stay that way until the object is Transformed again.

I really just need to know if I'm generally on the right track with my logic here, and if my planned scripts and objects they will be attached to is correct, or if I need to learn other principles. I'd like to avoid getting into bad habits early on!

I'm still learning the different sorts of variables and functions in the scripting etc, but what I was thinking:

I think I'd need three types of objects with their own script each, to achieve what I want...? 1. When clicked, plays specified sound at specified pitch 2. Selects the sound 3. Sets the pitch

Really rough pseudo-scripting (if it can even be called that!) below:

Object 1. When clicked, plays sound at pitch

   play{ 
   the sound declared by Object 2 at the pitch declared in Object 3
   }

I'm guessing this object would also need an Update function to pull the variables from the other objects on every frame so it always knows what the pitch should be?

Object 2. When clicked, selects which sound to play I'm not sure on the types of variables to use here..

var object var sound

if gameObject(1){ the sound gets changed to 1 else if gameObject(2) the sound gets changed to 2 etc, etc, etc }

Object 3. When clicked and dragged, changes the pitch of the sound being played

var pitch float = 1.0

 When the user clicks and drags the object {
   Transform.Rotate around single axis and set the "pitch" variable to a 
   number relative to its original rotation. So, as it Rotates one way,
   it would increment, the other way, it would decrease, and store variable
 }

Thanks guys, I'd really appreciate your feedback/advice.

(Edit: I just realised a simplification of what I want to do. You know how on some keyboards (musical) you have that little pitch bend wheel? My Object2 would be one of many keys, Object3 would be the key on the keyboard choosing your note, and imagine the sound wont play until Object1 is clicked, rather than when Object2 is.)

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 Nicolaj Schweitz · Apr 13, 2010 at 08:14 AM 0
Share

That is a long question I'd shorten it a bit to get sharp answers.

avatar image MooseTrap · Apr 16, 2010 at 03:42 AM 0
Share

Hmm... I thought I'd get less answers if I was too vague. I don't want to be one of those "I wanna do this! Give me code to Copy/Paste!" guys.

1 Reply

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

Answer by Nicolaj Schweitz · Apr 13, 2010 at 08:37 AM

Start by reading this overview of how audio works in Unity.

Then, go check the docs on audio.pitch.

Basically you can use any floating point to set the pitch of an audio source, so I guess you could take a specific axis of your Object 3, and convert that axis' angle to a reasonable float that can be used with audio.pitch. E.g. using Quaternion.eulerAngles.y

Another thing you would want to take a look at first, is how you can drag the rotation of Object 3. First have the mouse's screen position converted to a 3d world coordinate (e.g. Camera.ScreenPointToRay

Then set the object's rotation based on the mouse movement while the mouse button is down. You can fin several handy scripts for this on the UnifyCommunity wiki's script sections.

Good luck.

Comment
Add comment · Show 1 · 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 MooseTrap · Apr 16, 2010 at 03:43 AM 0
Share

Cheers! I'm away from my machine for a few days but I'll try as soon as I can. Thanks for the help! :-)

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

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Disabling a lineRender or Ray when there is no target 1 Answer

How to translate object one movement with script 1 Answer

Vector3 Transform.Position Not Working 2 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