AudioResource
Represents an audio resource asset that you can play through an AudioSource.
Read time 4 minutesLast updated 4 days ago
Definition
- Type: Class
- Namespace: UnityEngine.Audio
- Assembly: UnityEngine.AudioModule
- Inherits from: Object
public abstract class AudioResource : Object
Remarks
Note: Audio resources don’t provide direct access to properties like . However, if your audio resource is an AudioClip, you can access these properties through AudioSource.clip. Other types of resources might not provide direct access to these properties because the resources are dynamic or the values might change every time you play the audio.
lengthAdditional Resources: AudioClip, AudioRandomContainer.
Examples
using System.Collections;using UnityEngine;using UnityEngine.Audio;// Play an AudioClip, then an AudioResource, through an AudioSource.[RequireComponent(typeof(AudioSource))]public class ExampleClass : MonoBehaviour{ public AudioClip m_Clip; public AudioResource m_Resource; IEnumerator Start() { AudioSource audioSource = GetComponent<AudioSource>(); audioSource.resource = m_Clip; audioSource.Play(); yield return new WaitForSeconds(audioSource.clip.length); audioSource.resource = m_Resource; audioSource.Play(); }}
Inheritance
Operators
Operator | Description |
|---|---|
| operator == | Compares two object references to see if they refer to the same object. |
| bool | Determines whether the object exists. |
| operator != | Compares if two objects refer to a different object. |