Change pitch according to objects velocity?

Hi, I am trying to change the pitch of a sound attached to a game object depending on the velocity or speed of the object.

The main problem I am stuck at is I get an error due to the > symbol in the if statement.

Any ideas?

here is the code:

var startingPitch = 4;
var timeToDecrease = 5;
var speed = 1;

function Start() {
audio.pitch = startingPitch;

function Update() {

if(this.rigidbody.velocity  > speed )

	audio.pitch -= ((Time.deltaTime * startingPitch) / timeToDecrease);

your problem is that you are comparing a Vector3 with a float. You need to return the Vector as a Single number as compared to the Vector’s X, Y, and Z numbers. Unity provides the magnitude and the sqrMagnitude values for this purpose. (sqr magnitude takes less internal computations, so use it when possible).

Replace this line of code

if(this.rigidbody.velocity > speed )

with this one

if(this.rigidbody.velocity.sqrMagnitude > speed * speed )

or this one

if(this.rigidbody.velocity.magnitude > speed )

and it should work.