I’ve tried the exact same thing done in the lecture but the audio clips are still not playing
here is my code.
I have also added the audio clips in the inspector window of the player.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CollisionHandler : MonoBehaviour
{
[SerializeField] float delay=2f;
[SerializeField] AudioClip success;
[SerializeField] AudioClip fail;
AudioSource audioSource;
void Start()
{
audioSource=GetComponent<AudioSource>();
}
void OnCollisionEnter(Collision other)
{
switch(other.gameObject.tag)
{
case "Friendly":
Debug.Log("Friendly");
break;
case "Finish":
NextLevelSequence();
break;
default:
StartCrashSequence();
break;
}
void NextLevelSequence()
{
audioSource.PlayOneShot(success);
GetComponent<Movement>().enabled=false;
Invoke("NextLevel",delay);
}
void StartCrashSequence()
{
audioSource.PlayOneShot(fail);
GetComponent<Movement>().enabled=false;
Invoke("ReloadLevel",delay);
}
}
void ReloadLevel()
{
int currentSceneIndex=SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentSceneIndex);
}
void NextLevel()
{
int currentSceneIndex=SceneManager.GetActiveScene().buildIndex;
int nextSceneIndex=currentSceneIndex+1;
if(nextSceneIndex== SceneManager.sceneCountInBuildSettings)
{
nextSceneIndex=0;
}
SceneManager.LoadScene(nextSceneIndex);
}
}