Hi,
I have a game scene where when the player collides with an enemy, the player is destroyed and the scene restarts. But how can i have a collision sound effect play before the scene restarts?
I had assigned the AudioSource to the Player but I’m thinking it might not make sense if the payer is destroyed upon collision and if I want to have a collision sound effect.
Here’s some code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Player_Main : MonoBehaviour
{
public GameObject enemy_1; // Enemy is named Enemy
public AudioClip enemy_clip;
public AudioSource enemy_source;
void Start()
{
enemy_source.clip = enemy_clip;
}
void OnCollisionEnter(Collision col)
{
if
((col.gameObject.name == "Enemy"))
{
enemy_source.Play();
Destroy(player);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
}
Any help would be greatly appreciated. Thank you.