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
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..
Object 3. When clicked and dragged, changes the pitch of the sound being played
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.)
asked Apr 10 '10 at 12:23 PM
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.
answered Apr 13 '10 at 08:37 AM
Nicolaj Schweitz ♦♦