Two questions, and please explain well. First, how can I play an audio clip five seconds after the game starts?
Second, how can I play an audio clip when the player passes certain places in the level.
– ALSO, THIS IS A 2D PLATFORMER.
Two questions, and please explain well. First, how can I play an audio clip five seconds after the game starts?
Second, how can I play an audio clip when the player passes certain places in the level.
– ALSO, THIS IS A 2D PLATFORMER.
using UnityEngine; public class NewBehaviourScript : MonoBehaviour { //your source where the audio comes from public AudioSource audioSource; //your audio file public AudioClip audioClip; private void Start() { //starts the function in 5 seconds Invoke("PlayAudioClip", 5f); } private void PlayAudioClip() { //add the audio clip to the audiosource audioSource.clip = audioClip; //plays the audiosource audioSource.Play(); } //put the following into a script which is attached to the player gameObject private void OnTriggerEnter(Collider other) { //create a collider in unity and tick the box for "IsTrigger"; //also give the gameObject a tag named e.g.: "Level Event" if(other.tag == "Level Event") { PlayAudioClip(); } } }