So I have a script for an object that when shot explodes and it worked literally perfectly until I tried to add sound at which point it not only didn't play the sound but also stopped exploding, which was pretty rude of it.
Here's my code since I have no idea what's wrong: (Unity C#)
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShootyTarget : MonoBehaviour
{
public float health;
public GameObject destructionPrefab;
public GameObject explosion;
public GameObject shockwave;
public GameObject debris;
public AudioSource splodeSound;
void Start()
{
splodeSound = gameObject.GetComponent<AudioSource>();
}
void FuckingDie()
{
splodeSound.Play();
Instantiate(explosion, transform.position, transform.rotation);
Destroy(gameObject);
Instantiate(shockwave, transform.position, Quaternion.Euler(new Vector3(90, 0, 0)));
Instantiate(destructionPrefab, transform.position, transform.rotation);
Instantiate(debris, transform.position, transform.rotation);
}
public void takedamage(float amount)
{
health -= amount;
if (health <= 0f)
{
FuckingDie();
}
}
}
```