- Home /
What is wrong with my script to change audio pitch when accelerating?
I have made a JavaScript to make the pitch of my sound rise up to 3 over around 5 seconds while holding the up arrow but it says it has not finished compiling when I try to attach it to my car. If it helps I have made it in UnityDevelop as I have .net framework 4.5 not 3.5 and there is nothing showing compiling in the right bottom corner (what another forum suggested).
Here is the script:
//set startingPitch to 0.8 public var startingPitch = float; private var currentPitch = audio.pitch; @script RequireComponent(AudioSource) function Update() { if(Input.GetKey(KeyCode.UpArrow)){ current.Pitch = (Time.deltaTime 0.6 + startingPitch ); } { if((currentPitch > 3) currentPitch = (startingPitch 11.25); }else{ currentPitch = (startingpitch * 1); } }
What have I done wrong or is there a way I can fix this?
Please format your code using the 101010
button or indenting it by 4 spaces.
Answer by Nomibuilder · Jan 15, 2015 at 12:46 PM
audio.pitch = Mathf.Abs(EngineRPM / MaxEngineRPM) + 1.0f;
if (audio.pitch > 2.0f)
{
audio.pitch = 2.0f;
}
Answer by BenDurch · Apr 22, 2014 at 12:03 PM
The free flight controls package in the asset store has a script that changes pitch with velocity. you could chck it out.
Answer by tanoshimi · Jan 15, 2015 at 04:03 PM
public var startingPitch = float;
Should be:
public var startingPitch : float;