Controlling Pitch of Audio Source with the objects Position (Y position)

Hiya,

I’ve looked quite a lot online but cannot find what I need so thought it was about time I asked a question on here for the first time! I am a Digital Media student (with very little knowledge of any programming) and basically I am 10 days away from handing in my dissertation which is a project made with Leap Motion and Unity based around Audio in VR (so any help would be reeealy appreciated!)

I have a sphere in my scene which I can interact with using leap motion and it and it contains an audio source within the sphere. I am trying to figure out if its possible to control the pitch of the audio source by linking it to the objects Y position. So when the objects y position increases so does the pitch.

As I said any help would be amazing!!

Cheers!

I would probably create a script that does something similar to this:

public AudioSource audio;
function Update() {
	audio.pitch = transform.position.y;
}

You might still need to tweak it so that the pitch is in the correct range, but this should be a start. Here’s the documentation for changing the pitch from a script, in case it helps:

Hi, another question to add onto this – how do you convert the size of the screen so it could be used (from 0 - 1 i think?) for the pitch?

@Jawchewa