hi trying to play a sound on Destroy but it’s not playing I don’t know what I’m doing wrong really and not a lot I can explain
here’s the code maybe you experts can help me, it could just be me not looking at it the write way I don’t know
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Asteroids : MonoBehaviour
{
public float Torque;
public Rigidbody2D rb;
public GameObject asteroidLarge;
public GameObject asteroidSmall;
void Start()
{
float torque = (Torque);
rb.AddTorque(torque);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag ("bullet"))
{
Destroy(other.gameObject);
{
if (asteroidLarge);
Destroy(gameObject);
}
}
}
}
and here is the code for the SoundManagerScript
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoundManagerScript : MonoBehaviour
{
public static AudioClip PlayerDeathSound, playerBulletSound, enemyDeathSound, AsteroidExplosion01, AsteroidExplosion02, AsteroidExplosion03;
static AudioSource audioSrc;
void Start()
{
PlayerDeathSound = Resources.Load<AudioClip>("PlayerDeath");
playerBulletSound = Resources.Load<AudioClip>("Fire");
enemyDeathSound = Resources.Load<AudioClip>("EnemyDeath");
AsteroidExplosion01 = Resources.Load<AudioClip>("Asteroid01");
AsteroidExplosion02 = Resources.Load<AudioClip>("Asteroid02");
audioSrc = GetComponent<AudioSource>();
}
void Update()
{
}
public static void PlaySound (string clip)
{
switch (clip)
{
case "Asteroid01":
audioSrc.PlayOneShot(AsteroidExplosion01);
break;
}
}
}
I’ve been working on this for since 6 am and its 8 pm now and I’m getting tired and I’ve still got to figure out how to play an animation after destroy too, I gave up on that I couldn’t figure it out but 1 thing at a time
Regards
Andy