In my game I want audio to play when I am dead. I only want the clip to play once but with my current code, it loops. I don’t know why. Loop is turned off in the audio source component. Here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class DestroyPlayer : MonoBehaviour {
float deathCooldown = 5;
public bool dead;
public int value = 1;
public int yay = 3;
public AudioSource saw;
void Start () {
saw = GetComponent <AudioSource> ();
}
void OnCollisionEnter (Collision col)
{
if (col.gameObject.tag == "cup") {
ScorePoints.score += value;
Destroy (this.gameObject);
}
if (col.gameObject.tag == "Death") {
dead = true;
} else {
dead = false;
}
}
void Update()
{
if (dead == true) {
saw.Play ();
deathCooldown -= yay * Time.deltaTime;
GameObject.Find ("Cups").GetComponent <CupMovemnt> ().cupVelocity = 0f;
if (deathCooldown <= 0) {
SceneManager.LoadScene ("Scene");
}
}
}
}