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 priority: int;
int priority;
priority as int

Description

Sets the priority of the AudioSource.

Unity is virtualizing AudioSources, when there's more AudioSources playing than available hardware channels. The AudioSources with lowest priority (and audibility) is virtualized first. Priority is an integer between 0 and 255. 0=highest priority, 255=lowest priority.

	// occlude this sound if we dont have hardware resources to virtualize it

audio.priority = 255;

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Example() {
        audio.priority = 255;
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def Example() as void:
		audio.priority = 255