Legacy Documentation: Version 5.3
LanguageEnglish
  • C#
  • JS

Script language

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

AudioSource.pitch

Switch to Manual
public float pitch;

Description

The pitch of the audio source.

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(AudioSource))] public class ExampleClass : MonoBehaviour { public int startingPitch = 4; public int timeToDecrease = 5; AudioSource audio; void Start() { audio = GetComponent<AudioSource>(); audio.pitch = startingPitch; } void Update() { if (audio.pitch > 0) audio.pitch -= Time.deltaTime * startingPitch / timeToDecrease; } }