Version: 2017.3 (switch to 2017.4)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

AudioSource.pitch

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public var pitch: float;
public float pitch;

Description

The pitch of the audio source.

#pragma strict
@RequireComponent(AudioSource)
public var startingPitch: int = 4;
public var timeToDecrease: int = 5;
var audioSource: AudioSource;
function Start() {
	audioSource = GetComponent.<AudioSource>();
	audioSource.pitch = startingPitch;
}
function Update() {
	if (audioSource.pitch > 0)
		audioSource.pitch -= Time.deltaTime * startingPitch / timeToDecrease;
}
using UnityEngine;
using System.Collections;

[RequireComponent(typeof(AudioSource))] public class ExampleClass : MonoBehaviour { public int startingPitch = 4; public int timeToDecrease = 5; AudioSource audioSource;

void Start() { audioSource = GetComponent<AudioSource>(); audioSource.pitch = startingPitch; }

void Update() { if (audioSource.pitch > 0) audioSource.pitch -= Time.deltaTime * startingPitch / timeToDecrease; } }

Did you find this page useful? Please give it a rating: