Scripting with audio and video
In this section, we will explore how to interact with the audio and video systems via C# scripts. Similar to the previous section, we will also introduce the C# methods for Audio Source and Video Player respectively. We first start with the C# methods for Audio Source.
AudioSource.Play
The first function we will introduce is the Play function of AudioSource. The function signature of Play is as follows:
public void Play();
It is very simple and straightforward to call this function to play an audio clip. However, if you need to deal with more complex scenarios, such as delaying the playback of an audio clip, you can call the PlayDelayed function, which will play the clip with a delay specified in seconds.
Note
There was an overloaded version of the Play function, which requires a delay parameter. However, it's deprecated now. Developers are advised to use the PlayDelayed function instead of the old Play (delay) function.
The...