Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

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

var pitch: float;
float pitch;
pitch as float

Description

The pitch of the audio source.

	// Decreases the pitch in the given seconds

var startingPitch = 4; var timeToDecrease = 5; @script RequireComponent(AudioSource) function Start() { audio.pitch = startingPitch; }

function Update() { if(audio.pitch > 0) audio.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;
    void Start() {
        audio.pitch = startingPitch;
    }
    void Update() {
        if (audio.pitch > 0)
            audio.pitch -= Time.deltaTime * startingPitch / timeToDecrease;
        
    }
}
import UnityEngine
import System.Collections

[RequireComponent(typeof(AudioSource))]
public class ExampleClass(MonoBehaviour):

	public startingPitch as int = 4

	public timeToDecrease as int = 5

	def Start() as void:
		audio.pitch = startingPitch

	def Update() as void:
		if audio.pitch > 0:
			audio.pitch -= ((Time.deltaTime * startingPitch) / timeToDecrease)